Skip to content

Commit fd05195

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 fd05195

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test/common/proxy-server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ 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+
if (!res.writableEnded) {
95+
res.write('HTTP/1.1 500 Connection Error\r\n\r\n');
96+
res.end('Proxy error: ' + err.message);
97+
}
9698
});
9799
});
98100

0 commit comments

Comments
 (0)