Skip to content

fix(net): keep guest data queued before connect on a guest half-close - #160

Open
TadahiroYamamura wants to merge 1 commit into
earendil-works:mainfrom
TadahiroYamamura:fix/tcp-keep-pending-writes-on-guest-fin
Open

TadahiroYamamura wants to merge 1 commit into
earendil-works:mainfrom
TadahiroYamamura:fix/tcp-keep-pending-writes-on-guest-fin

Conversation

@TadahiroYamamura

Copy link
Copy Markdown

A5 of #155.

Problem
On mapped TCP, when data and a FIN arrive before the upstream connect() finishes, the already-ACKed data is discarded before end(). When the guest sent 5 bytes and closed immediately, the upstream server received 0 bytes (waiting 0.5s before closing, all 5 bytes arrived).

Fix
On a graceful close (destroy: false), write the queued data to the connecting socket before end(). Node's socket sends written data before the FIN. With destroy: true the data is still discarded as before.

Tests
Connect over mapped TCP to a server listening on 127.0.0.1, feed data and a FIN before the connection completes, and check that the server receives all bytes before the FIN.

Please check

  • The data written on close was already checked against the cap (maxTcpPendingWriteBytes) when it was queued, so the cap is not exceeded. The writableLength check done for connected sockets is not applied, since no new guest data arrives after the FIN
  • If the upstream connection fails, the queued data is still discarded as before and the guest gets an RST

Suggested CHANGELOG entry
Fix data the guest sent over a mapped TCP connection being dropped when the guest half-closed before the upstream connect finished.

🤖 AI (Claude Code) was used for the investigation and for writing the code.

Contribution Agreement

Please ensure this PR follows the guidelines in CONTRIBUTING.md.

By submitting this pull request, I confirm the following:

I understand that the entity Earendil Inc. (incorporated in the state of Delaware in 2025) needs some rights from me in order to utilize my contributions in this PR. As a contributor I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Earendil Inc. can use, modify, copy, and redistribute my contributions, under Earendil Inc.'s choice of terms.

On mapped TCP, data and a FIN arriving before the upstream connect()
finished made us discard the already-acked data before end(). On a
graceful close, write the data to the connecting socket before end();
Node sends written data before the FIN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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