Skip to content

fix(socks5-proxy-agent): destroy socket when negotiation times out - #5709

Merged
metcoder95 merged 1 commit into
nodejs:mainfrom
abhijeet117:fix/socks5-negotiation-timeout-socket-leak
Aug 25, 2026
Merged

fix(socks5-proxy-agent): destroy socket when negotiation times out#5709
metcoder95 merged 1 commit into
nodejs:mainfrom
abhijeet117:fix/socks5-negotiation-timeout-socket-leak

Conversation

@abhijeet117

Copy link
Copy Markdown
Contributor

Summary

When SOCKS5 authentication or connection negotiation times out, createSocks5Connection() rejects its promise but never destroys the underlying socket. The socket also never reaches the per-origin pool because the connect callback is only invoked on success, so close() and destroy() cannot reach it and it stays open for the lifetime of the process. This destroys the client in both timeout branches before rejecting.

Testing

Reproduced with a local TCP proxy that accepts a connection but never replies to the greeting: the request rejects with "SOCKS5 authentication timeout", after which agent.close() leaves the socket open. Added a regression test in test/socks5-proxy-agent.js that asserts the connector socket is destroyed after close; it fails without this change and passes with it. All socks5 test files pass (33 pass, 1 skipped) and eslint is clean.

Checklist

  • bug reproduced before fix
  • root cause identified
  • bug fixed
  • tests passed

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@codecov-commenter

codecov-commenter commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.47%. Comparing base (5033aa1) to head (5474255).

Files with missing lines Patch % Lines
lib/dispatcher/socks5-proxy-agent.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5709   +/-   ##
=======================================
  Coverage   93.47%   93.47%           
=======================================
  Files         110      110           
  Lines       38906    38908    +2     
=======================================
+ Hits        36366    36370    +4     
+ Misses       2540     2538    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@metcoder95
metcoder95 merged commit fc3450d into nodejs:main Aug 25, 2026
36 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants