Skip to content

close failed v2ray upgrade connections#4241

Draft
winter-loo wants to merge 1 commit into
SagerNet:testingfrom
winter-loo:codex/close-failed-v2ray-upgrade-connections
Draft

close failed v2ray upgrade connections#4241
winter-loo wants to merge 1 commit into
SagerNet:testingfrom
winter-loo:codex/close-failed-v2ray-upgrade-connections

Conversation

@winter-loo

Copy link
Copy Markdown

Summary

  • close the underlying TCP connection when a v2ray WebSocket upgrade fails after dialing
  • close the underlying TCP connection when a v2ray HTTP Upgrade handshake fails after dialing
  • close the HTTP Upgrade response body on unexpected upgrade status

Root cause

Both transport clients open a lower-level TCP connection before validating the upgrade handshake. Some failure paths returned without closing that connection, so repeated failed URL tests could retain socket/AFD handles on Windows even though they no longer appeared as active established TCP connections.

Validation

  • Built a patched Windows binary from v1.13.13 and replaced the running sing-box process.
  • Before the fix, repeated URL tests caused sing-box handles, AFD handles, and TCP Bound endpoints to grow into the thousands, eventually producing Windows 10055 / insufficient buffer space errors.
  • After the fix, the process was monitored for many hours with handles staying around 540-565, AFD handles around 50-80, TCP Bound endpoints in single/double digits, and proxy/API ports remaining reachable.

@nekohasekai nekohasekai force-pushed the testing branch 2 times, most recently from 22fe3b6 to b2d51f6 Compare June 29, 2026 03:43
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@winter-loo winter-loo force-pushed the codex/close-failed-v2ray-upgrade-connections branch from 1c87b6c to 535434f Compare June 29, 2026 18:46
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.

1 participant