#4616·undici

在代理文件流时,Windows 命名管道会卡死

作者: danielroe创建于 2025年10月7日更新于 2026年8月31日
标签bug

// Create ~2MB test file async function createTestFile() { await mkdir(TEST_DIR, { recursive: true }) const content = 'x'.repeat(2_000_000) // 2MB await writeFile(TEST_FILE, content) console.log(Created ${content.length} byte test file\n) }

// Server that streams a file const fileServer = createServer(async (req, res) => { const stats = await stat(TEST_FILE) res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': stats.size, }) createReadStream(TEST_FILE).pipe(res) })

const proxyUndici = createServer(async (req, res) => { console.log('[Proxy] Received request, fetching from file server via undici...')

const agent = new Agent({ connect: { socketPath } }) const response = await fetch('http://localhost/', { dispatcher: agent })

console.log([Proxy] Got response: ${response.status} ${response.statusText}) console.log([Proxy] Headers:, Object.fromEntries(response.headers))

res.writeHead(response.status, Object.fromEntries(response.headers))

const reader = response.body.getReader() let chunks = 0 let totalBytes = 0