Skip to content

fix(ws): skip writing to closed socket on non-upgrade response#114

Merged
pi0 merged 1 commit intomainfrom
fix/ws-close-before-response
Mar 25, 2026
Merged

fix(ws): skip writing to closed socket on non-upgrade response#114
pi0 merged 1 commit intomainfrom
fix/ws-close-before-response

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Mar 25, 2026

Summary

  • Check socket.writable before writing the HTTP response when the upstream does not upgrade the WebSocket connection
  • Prevents uncatchable "This socket has been ended by the other party" errors when the client disconnects before the non-upgrade response arrives
  • Applied to both ws-incoming.ts (ProxyServer middleware) and ws.ts (standalone proxyUpgrade)

Upstream: http-party/node-http-proxy#1552

Test plan

  • Regression test added in test/ws.test.ts — verifies socket.write() is not called when the socket is destroyed before the non-upgrade response
  • Test fails without the fix, passes with it
  • Full test suite passes (229 tests)

Check socket.writable before writing the HTTP response when the upstream
does not upgrade the connection. Prevents uncatchable "socket has been
ended" errors when the client disconnects before the response arrives.

Upstream: http-party/node-http-proxy#1552
@pi0 pi0 merged commit d11c6eb into main Mar 25, 2026
4 checks passed
@pi0 pi0 deleted the fix/ws-close-before-response branch March 25, 2026 19:56
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.55%. Comparing base (8724245) to head (7a7e97b).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #114      +/-   ##
==========================================
+ Coverage   96.14%   97.55%   +1.40%     
==========================================
  Files           8        8              
  Lines         623      695      +72     
  Branches      233      279      +46     
==========================================
+ Hits          599      678      +79     
+ Misses         24       17       -7     

☔ View full report in Codecov by Sentry.
📢 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.

1 participant