diff --git a/tests/third_party/proxy/index.ts b/tests/third_party/proxy/index.ts index 1b296bff6a..6fbd3e9407 100644 --- a/tests/third_party/proxy/index.ts +++ b/tests/third_party/proxy/index.ts @@ -3,6 +3,7 @@ import * as net from 'net'; import * as url from 'url'; import * as http from 'http'; import * as os from 'os'; +import { pipeline } from 'stream/promises'; const pkg = { version: '1.0.0' } @@ -475,13 +476,19 @@ function onupgrade(req: http.IncomingMessage, socket: net.Socket, head: Buffer) localAddress: this.localAddress, }); - proxyReq.on('upgrade', function (proxyRes, proxySocket, proxyHead) { + proxyReq.on('upgrade', async function (proxyRes, proxySocket, proxyHead) { const header = ['HTTP/1.1 101 Switching Protocols']; for (const [key, value] of Object.entries(proxyRes.headersDistinct)) header.push(`${key}: ${value}`); socket.write(header.join('\r\n') + '\r\n\r\n'); if (proxyHead && proxyHead.length) proxySocket.unshift(proxyHead); - proxySocket.pipe(socket).pipe(proxySocket); + + try { + await pipeline(proxySocket, socket, proxySocket); + } catch (error) { + if (error.code !== "ECONNRESET") + throw error; + } }); proxyReq.end(head);