René's URL Explorer Experiment


Title: `ClientRequest` emits `error` event with `ERR_PROXY_TUNNEL` twice · Issue #60697 · nodejs/node · GitHub

Open Graph Title: `ClientRequest` emits `error` event with `ERR_PROXY_TUNNEL` twice · Issue #60697 · nodejs/node

X Title: `ClientRequest` emits `error` event with `ERR_PROXY_TUNNEL` twice · Issue #60697 · nodejs/node

Description: Version v25.2.0 (affects v24 identically) Platform Linux d4e4f8af51de 6.11.11-linuxkit #1 SMP Wed Oct 22 09:37:46 UTC 2025 aarch64 GNU/Linux Subsystem https What steps will reproduce the bug? I used Docker to test: docker run --rm \ -e H...

Open Graph Description: Version v25.2.0 (affects v24 identically) Platform Linux d4e4f8af51de 6.11.11-linuxkit #1 SMP Wed Oct 22 09:37:46 UTC 2025 aarch64 GNU/Linux Subsystem https What steps will reproduce the bug? I use...

X Description: Version v25.2.0 (affects v24 identically) Platform Linux d4e4f8af51de 6.11.11-linuxkit #1 SMP Wed Oct 22 09:37:46 UTC 2025 aarch64 GNU/Linux Subsystem https What steps will reproduce the bug? I use...

Opengraph URL: https://github.com/nodejs/node/issues/60697

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`ClientRequest` emits `error` event with `ERR_PROXY_TUNNEL` twice","articleBody":"### Version\n\nv25.2.0 (affects v24 identically)\n\n### Platform\n\n```text\nLinux d4e4f8af51de 6.11.11-linuxkit #1 SMP Wed Oct 22 09:37:46 UTC 2025 aarch64 GNU/Linux\n```\n\n### Subsystem\n\nhttps\n\n### What steps will reproduce the bug?\n\nI used Docker to test:\n\n```bash\ndocker run --rm \\\n  -e HTTPS_PROXY=http://google.com \\\n  -e NODE_USE_ENV_PROXY=1 \\\n  node:25.2.0 -e 'require(\"https\").request(\"https://wherever\").on(\"error\", console.error)'\n```\n\nEquivalent plain command line:\n\n```bash\nHTTPS_PROXY=http://google.com NODE_USE_ENV_PROXY=1 \\\n  node -e 'require(\"https\").request(\"https://wherever\").on(\"error\", console.error)'\n```\n\n### How often does it reproduce? Is there a required condition?\n\nIt reproduces reliably. Conditions are:\n- enable using an HTTPS proxy from the environment, with `NODE_USE_ENV_PROXY=1` (or `--use-env-proxy`)\n- use a proxy that will reject the tunnel request (I'm using `http://google.com` here which will obviously reject tunneling requests)\n\n\n\n### What is the expected behavior? Why is that the expected behavior?\n\nI expected the `error` event to only be emitted once. This is what happens with other types of error, for example if the proxy itself cannot be resolved (`ENOTFOUND`) or it rejects the connection (`ECONNRESET`).\n\n### What do you see instead?\n\nInstead, the `error` event is emitted twice.\n\nThis is a concern because an unhandled `error` event will abort the process, so code that handles the expects `error` to only be emitted once and uses `EventEmitter.once` or `events.once` can break.\n\nFor example, this fails with an unhandled `error` event, after printing out the first `error` event:\n\n```bash\n$ HTTPS_PROXY=http://google.com NODE_USE_ENV_PROXY=1  \\\n  node -e 'require(\"https\").request(\"https://wherever\").once(\"error\", console.error)'\n\nError [ERR_PROXY_TUNNEL]: Failed to establish tunnel to wherever:443 via http://google.com: HTTP/1.1 404 Not Found\n    at onProxyData (node:https:256:19)\n    at Socket.read (node:https:220:11)\n    at Socket.emit (node:events:508:28)\n    at emitReadable_ (node:internal/streams/readable:832:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:88:21) {\n  code: 'ERR_PROXY_TUNNEL',\n  statusCode: 404\n}\nnode:events:486\n      throw er; // Unhandled 'error' event\n      ^\n\nError [ERR_PROXY_TUNNEL]: Failed to establish tunnel to wherever:443 via http://google.com: HTTP/1.1 404 Not Found\n    at onProxyData (node:https:256:19)\n    at Socket.read (node:https:220:11)\n    at Socket.emit (node:events:508:28)\n    at emitReadable_ (node:internal/streams/readable:832:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:88:21)\nEmitted 'error' event on ClientRequest instance at:\n    at emitErrorEvent (node:_http_client:108:11)\n    at _destroy (node:_http_client:962:9)\n    at onSocketNT (node:_http_client:982:5)\n    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {\n  code: 'ERR_PROXY_TUNNEL',\n  statusCode: 404\n}\n\nNode.js v25.2.0\n\n$ echo $?\n1\n```\n\n### Additional information\n\nIt may be argued that `error` being emitted only once isn't really guaranteed (that I could find), so here is an illustration of how existing code can rely on such behaviour. We encountered this when trying to use https://github.com/panva/openid-client v5.7.0 (version 6 uses `fetch` so is not affected) in conjunction with `NODE_USE_ENV_PROXY`. The code in `openid-client` uses `events.once` together with `Promise.race` to wait for either the `response` or `timeout` events to occur on the `ClientRequest`: https://github.com/panva/openid-client/blob/45c96f67ce0644bd829f61e82fba3dd8c051c89e/lib/helpers/request.js#L135\n\n```js\n    [response] = await Promise.race([once(req, 'response'), once(req, 'timeout')]);\n```\n\nThis relies on the fact that `events.once` will also listen to the `error` event. But it will unsubscribe from `error` after the first event, so the process crashes as the second `error` event is emitted.\n\nHere's a reproduction of the issue as encountered, assuming `npm install openid-client@5.7.0`.\n\nThis scenario, where the proxy refuses to establish a tunnel, fails with an `Unhandled 'error' event` crash:\n\n```bash\n$ HTTPS_PROXY=http://google.com NODE_USE_ENV_PROXY=1 \\\n  node -e 'require(\"openid-client\").Issuer.discover(\"https://wherever\").then(console.log, console.error);'\n\nnode:events:486\n      throw er; // Unhandled 'error' event\n      ^\n\nError [ERR_PROXY_TUNNEL]: Failed to establish tunnel to wherever:443 via http://google.com: HTTP/1.1 404 Not Found\n    at onProxyData (node:https:256:19)\n    at Socket.read (node:https:220:11)\n    at Socket.emit (node:events:508:28)\n    at emitReadable_ (node:internal/streams/readable:832:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:89:21)\nEmitted 'error' event on ClientRequest instance at:\n    at emitErrorEvent (node:_http_client:107:11)\n    at _destroy (node:_http_client:954:9)\n    at onSocketNT (node:_http_client:974:5)\n    at process.processTicksAndRejections (node:internal/process/task_queues:91:21) {\n  code: 'ERR_PROXY_TUNNEL',\n  statusCode: 404\n}\n\n$ echo $?\n1\n```\n\nThis one, where the proxy cannot be resolved, has a saner behaviour (the same as when no proxy is involved) of rejecting the promise returned by `discover()`, allowing recovery:\n\n```bash\n$ HTTPS_PROXY=http://proxy.invalid NODE_USE_ENV_PROXY=1 \\\n  node -e 'require(\"openid-client\").Issuer.discover(\"https://wherever\").then(console.log, console.error);'\n\nError: getaddrinfo ENOTFOUND proxy.invalid\n    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:122:26) {\n  errno: -3008,\n  code: 'ENOTFOUND',\n  syscall: 'getaddrinfo',\n  hostname: 'proxy.invalid'\n}\n\n$ echo $?\n0\n```\n","author":{"url":"https://github.com/jonathanperret","@type":"Person","name":"jonathanperret"},"datePublished":"2025-11-12T21:13:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/60697/node/issues/60697"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:4a2a60e1-c672-0d91-65e6-de3c6b4dd612
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA230:AF0A5:2456B3:3117B5:6A4D3398
html-safe-nonce66bcd844f8dc138fed103c61e6767dc71f4b7bea913447d8eccc34f6c30ece78
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjMwOkFGMEE1OjI0NTZCMzozMTE3QjU6NkE0RDMzOTgiLCJ2aXNpdG9yX2lkIjoiODc3OTAxMTIxMzIwNTc3OTM1MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9532ef403d532541f73570a4056b107c9b85fef98487226cda3828291008a249
hovercard-subject-tagissue:3618256213
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/60697/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9fe0f7cd23377699fd0b6f39df513195c4796488f3a0adca4883adadadb9ae39/nodejs/node/issues/60697
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9fe0f7cd23377699fd0b6f39df513195c4796488f3a0adca4883adadadb9ae39/nodejs/node/issues/60697
og:image:altVersion v25.2.0 (affects v24 identically) Platform Linux d4e4f8af51de 6.11.11-linuxkit #1 SMP Wed Oct 22 09:37:46 UTC 2025 aarch64 GNU/Linux Subsystem https What steps will reproduce the bug? I use...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejonathanperret
hostnamegithub.com
expected-hostnamegithub.com
None92571a8944142227b7e19cd10918b1ddd06e5066c1ad5bc7e4769cf6140a87e6
turbo-cache-controlno-preview
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release56fc8347865a14e2ec811533d68f929cf4e0ec19
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/nodejs/node/issues/60697#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F60697
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F60697
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/issues/60697
Reloadhttps://github.com/nodejs/node/issues/60697
Reloadhttps://github.com/nodejs/node/issues/60697
Please reload this pagehttps://github.com/nodejs/node/issues/60697
nodejs https://github.com/nodejs
nodehttps://github.com/nodejs/node
Please reload this pagehttps://github.com/nodejs/node/issues/60697
Notifications https://github.com/login?return_to=%2Fnodejs%2Fnode
Fork 36k https://github.com/login?return_to=%2Fnodejs%2Fnode
Star 118k https://github.com/login?return_to=%2Fnodejs%2Fnode
Code https://github.com/nodejs/node
Issues 1.4k https://github.com/nodejs/node/issues
Pull requests 957 https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality 0 https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
Code https://github.com/nodejs/node
Issues https://github.com/nodejs/node/issues
Pull requests https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
#60699https://github.com/nodejs/node/pull/60699
ClientRequest emits error event with ERR_PROXY_TUNNEL twicehttps://github.com/nodejs/node/issues/60697#top
#60699https://github.com/nodejs/node/pull/60699
https://github.com/jonathanperret
jonathanperrethttps://github.com/jonathanperret
on Nov 12, 2025https://github.com/nodejs/node/issues/60697#issue-3618256213
https://github.com/panva/openid-clienthttps://github.com/panva/openid-client
https://github.com/panva/openid-client/blob/45c96f67ce0644bd829f61e82fba3dd8c051c89e/lib/helpers/request.js#L135https://github.com/panva/openid-client/blob/45c96f67ce0644bd829f61e82fba3dd8c051c89e/lib/helpers/request.js#L135
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.