Skip to content

close failed v2ray upgrade connections#4241

Open
winter-loo wants to merge 132 commits into
SagerNet:testingfrom
winter-loo:codex/close-failed-v2ray-upgrade-connections
Open

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

Conversation

@winter-loo

@winter-loo winter-loo commented Jun 25, 2026

Copy link
Copy Markdown

Problem

ERROR gateway.platforms.base: [Discord] Fallback send also failed: Cannot connect to host localhost:6780 ssl:default [由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。]
Cannot connect to host localhost:6780
[WinError 10055] 系统缓冲区空间不足或队列已满

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 11 times, most recently from 77c44b3 to 5cd932a Compare July 15, 2026 16:38
@nekohasekai
nekohasekai force-pushed the testing branch 19 times, most recently from 41f736e to 5d744ad Compare July 23, 2026 13:08
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.

3 participants