Skip to content

fix: destroy socket on SOCKS5 negotiation timeout - #5706

Open
mcollina wants to merge 1 commit into
mainfrom
fix/5704-socks5-socket-leak
Open

fix: destroy socket on SOCKS5 negotiation timeout#5706
mcollina wants to merge 1 commit into
mainfrom
fix/5704-socks5-socket-leak

Conversation

@mcollina

Copy link
Copy Markdown
Member

Fixes #5704

Socks5ProxyAgent's createSocks5Connection() rejected its promises on the SOCKS5 auth and CONNECT negotiation timeouts without destroying the underlying socket. Because the socket is never handed to the per-origin Pool (the connect callback that would register it is never reached), it's completely untracked — agent.close()/agent.destroy() only iterate this[kPools], so neither can reach it. A proxy that accepts the TCP connection but stalls during negotiation leaks one open socket per attempt for the lifetime of the process.

This calls socks5Client.destroy() in both timeout paths before rejecting, tearing down the socket (matching the cleanup already done on the error path).

A regression test spins up a proxy that accepts the connection, drains the SOCKS5 greeting, but never replies, then verifies the proxy-side socket is destroyed after the request rejects and agent.close() resolves.

Socks5ProxyAgent's createSocks5Connection() rejected its promises on the
auth and CONNECT timeouts without destroying the underlying socket. Because
the socket was never handed to the per-origin Pool, agent.close()/destroy()
could not reach it and it leaked open for the process lifetime.

Destroy the socket in both timeout paths before rejecting.
@codecov-commenter

codecov-commenter commented Aug 21, 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 (dd85997) to head (db85942).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
lib/dispatcher/socks5-proxy-agent.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5706      +/-   ##
==========================================
+ Coverage   93.43%   93.47%   +0.03%     
==========================================
  Files         110      110              
  Lines       38733    38894     +161     
==========================================
+ Hits        36190    36355     +165     
+ Misses       2543     2539       -4     

☔ 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.

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.

Socks5ProxyAgent: SOCKS5 handshake/auth timeout leaks the underlying socket

2 participants