Skip to content

fix(web-incoming): defer pipe until socket connects#111

Merged
pi0 merged 1 commit intomainfrom
fix/body-data-loss-pipe
Mar 25, 2026
Merged

fix(web-incoming): defer pipe until socket connects#111
pi0 merged 1 commit intomainfrom
fix/body-data-loss-pipe

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Mar 25, 2026

Summary

  • Defer pipe() of request body into proxyReq until the underlying socket is connected, preventing body data loss when the same request is retried against an alternate target
  • Add regression test verifying POST body integrity through the proxy

Context

Upstream PR: http-party/node-http-proxy#1495

When pipe() is called before the socket connects, the request body stream is consumed eagerly. If the connection fails and the caller retries proxy.web() with the same req against a different target, the body has already been drained and is lost.

The fix checks socket.pending inside the socket event — if pending, it waits for connect before piping; if already connected (reused socket), it pipes immediately.

The forward path is left unchanged since it's fire-and-forget and doesn't have retry semantics.

Test plan

  • New test: POST with 8KB body is fully delivered through proxy
  • All 230 existing tests pass

Avoid piping request body into proxyReq before the underlying socket is
connected. Piping eagerly can consume the request stream, causing body
data loss when retrying the same request to an alternate target.

Ref: http-party/node-http-proxy#1495
@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 10 minutes and 24 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: 8d1f767a-e2e3-4a57-8f7b-6a4618605bf6

📥 Commits

Reviewing files that changed from the base of the PR and between 11f3657 and 622cad1.

📒 Files selected for processing (2)
  • src/middleware/web-incoming.ts
  • test/middleware/web-incoming.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/body-data-loss-pipe

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

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.36%. Comparing base (8724245) to head (622cad1).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/middleware/web-incoming.ts 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
+ Coverage   96.14%   97.36%   +1.22%     
==========================================
  Files           8        8              
  Lines         623      684      +61     
  Branches      233      273      +40     
==========================================
+ Hits          599      666      +67     
+ Misses         24       18       -6     

☔ 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 pi0 mentioned this pull request Mar 25, 2026
58 tasks
@pi0 pi0 merged commit 7f74a06 into main Mar 25, 2026
6 of 7 checks passed
@pi0 pi0 deleted the fix/body-data-loss-pipe branch March 25, 2026 20:28
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