Skip to content

Commit 2e944d7

Browse files
authored
http,https: fix double ERR_PROXY_TUNNEL emission
Fixes: #60697 PR-URL: #60699 Reviewed-By: Tim Perry <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
1 parent 44ed25a commit 2e944d7

6 files changed

+7
-7
lines changed

lib/_http_agent.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,8 @@ function handleSocketAfterProxy(err, req) {
284284
if (err.code === 'ERR_PROXY_TUNNEL') {
285285
if (err.proxyTunnelTimeout) {
286286
req.emit('timeout'); // Propagate the timeout from the tunnel to the request.
287-
} else {
288-
req.emit('error', err);
289287
}
288+
req.emit('error', err);
290289
}
291290
}
292291

lib/_http_client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,8 @@ function onSocketNT(req, socket, err) {
958958
if (!req.aborted && !err) {
959959
err = new ConnResetException('socket hang up');
960960
}
961-
if (err) {
961+
// ERR_PROXY_TUNNEL is handled by the proxying logic
962+
if (err && err.code !== 'ERR_PROXY_TUNNEL') {
962963
emitErrorEvent(req, err);
963964
}
964965
req._closed = true;

test/client-proxy/test-https-proxy-request-malformed-response.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const { code, signal, stderr, stdout } = await runProxiedRequest({
4343
});
4444

4545
// The proxy client should get an error from failure in establishing the tunnel.
46-
assert.match(stderr, /ERR_PROXY_TUNNEL.*Failed to establish tunnel to .* NOT-HTTP MALFORMED RESPONSE/);
46+
assert.strictEqual(stderr.match(/ERR_PROXY_TUNNEL.*Failed to establish tunnel to .* NOT-HTTP MALFORMED RESPONSE*/g).length, 1);
4747
assert.strictEqual(stdout.trim(), '');
4848
assert.strictEqual(code, 0);
4949
assert.strictEqual(signal, null);

test/client-proxy/test-https-proxy-request-proxy-failure-404.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const { code, signal, stderr, stdout } = await runProxiedRequest({
4343
});
4444

4545
// The proxy client should get an error from failure in establishing the tunnel.
46-
assert.match(stderr, /ERR_PROXY_TUNNEL.*Failed to establish tunnel to .* HTTP\/1\.1 404 Not Found/);
46+
assert.strictEqual(stderr.match(/ERR_PROXY_TUNNEL.*Failed to establish tunnel to .* HTTP\/1\.1 404 Not Found/g).length, 1);
4747
assert.strictEqual(stdout.trim(), '');
4848
assert.strictEqual(code, 0);
4949
assert.strictEqual(signal, null);

test/client-proxy/test-https-proxy-request-proxy-failure-500.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const { code, signal, stderr, stdout } = await runProxiedRequest({
4444
});
4545

4646
// The proxy client should get an error from failure in establishing the tunnel.
47-
assert.match(stderr, /ERR_PROXY_TUNNEL.*Failed to establish tunnel to .* HTTP\/1\.1 500 Connection Error/);
47+
assert.strictEqual(stderr.match(/ERR_PROXY_TUNNEL.*Failed to establish tunnel to .* HTTP\/1\.1 500 Connection Error/g).length, 1);
4848
assert.strictEqual(stdout.trim(), '');
4949
assert.strictEqual(code, 0);
5050
assert.strictEqual(signal, null);

test/client-proxy/test-https-proxy-request-proxy-failure-502.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const { code, signal, stderr, stdout } = await runProxiedRequest({
4242
});
4343

4444
// The proxy client should get an error from failure in establishing the tunnel.
45-
assert.match(stderr, /ERR_PROXY_TUNNEL.*Failed to establish tunnel to .* HTTP\/1\.1 502 Bad Gateway/);
45+
assert.strictEqual(stderr.match(/ERR_PROXY_TUNNEL.*Failed to establish tunnel to .* HTTP\/1\.1 502 Bad Gateway/g).length, 1);
4646
assert.strictEqual(stdout.trim(), '');
4747
assert.strictEqual(code, 0);
4848
assert.strictEqual(signal, null);

0 commit comments

Comments
 (0)