Skip to content

Commit ac8039d

Browse files
committed
test: guard write to proxy client if proxy connection is ended
In the testing proxy server for proxy client tests, the proxy client might have already closed the connection when the upstream connection fails. In that case, there's no need for the proxy server to inform the proxy client about the error.
1 parent 961554c commit ac8039d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

test/common/proxy-server.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ exports.createProxyServer = function(options = {}) {
9191

9292
proxyReq.on('error', (err) => {
9393
logs.push({ error: err, source: 'proxy request' });
94-
res.write('HTTP/1.1 500 Connection Error\r\n\r\n');
95-
res.end('Proxy error: ' + err.message);
94+
// The proxy client might have already closed the connection
95+
// when the upstream connection fails.
96+
if (!res.writableEnded) {
97+
res.write('HTTP/1.1 500 Connection Error\r\n\r\n');
98+
res.end('Proxy error: ' + err.message);
99+
}
96100
});
97101
});
98102

0 commit comments

Comments
 (0)