Skip to content

fix(ws): guard against writing to destroyed socket#113

Closed
pi0 wants to merge 0 commit intomainfrom
fix/write-destroyed-socket
Closed

fix(ws): guard against writing to destroyed socket#113
pi0 wants to merge 0 commit intomainfrom
fix/write-destroyed-socket

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Mar 25, 2026

Summary

  • Check socket.destroyed and socket.writable before writing a non-upgrade HTTP response back to the client socket in WS proxy paths
  • Applies to both ProxyServer.ws() (middleware) and standalone proxyUpgrade()
  • In proxyUpgrade(), the rejection promise is now always fired for non-upgrade responses regardless of socket state

Upstream reference: http-party/node-http-proxy#1433

Test plan

  • Added regression test that destroys the client socket before the upstream non-upgrade response arrives
  • Tests both ProxyServer.ws() and proxyUpgrade() code paths
  • Full test suite passes (230 tests)

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

Warning

Rate limit exceeded

@pi0 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 27 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a2d2c707-69ea-4c9e-9a2b-979d93ecc8ee

📥 Commits

Reviewing files that changed from the base of the PR and between b7075ab and ea290d0.

📒 Files selected for processing (3)
  • src/middleware/ws-incoming.ts
  • src/ws.ts
  • test/ws-destroyed-socket.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/write-destroyed-socket

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@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 95.97%. Comparing base (b7075ab) to head (ea290d0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #113      +/-   ##
==========================================
- Coverage   96.11%   95.97%   -0.15%     
==========================================
  Files           8        8              
  Lines         644      646       +2     
  Branches      244      244              
==========================================
+ Hits          619      620       +1     
  Misses         24       24              
- Partials        1        2       +1     

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

@pi0
Copy link
Copy Markdown
Member Author

pi0 commented Mar 25, 2026

Closing — the fix in this PR was fully superseded by #116, which covers the same destroyed-socket guards in ws-incoming.ts and ws.ts plus adds res.on("error") handling for upstream response stream errors.

@pi0 pi0 deleted the fix/write-destroyed-socket branch March 25, 2026 20:12
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