Repository navigation
fix(net): send our FIN when the guest closes before any payload - #159
Open
TadahiroYamamura wants to merge 1 commit into
Open
TadahiroYamamura wants to merge 1 commit into
TadahiroYamamura wants to merge 1 commit into
Conversation
Before the first payload there is no upstream socket, so when the guest closed first Gondolin never sent a FIN: the guest stayed in FIN-WAIT-2 and the natTable entry stayed behind. Send our FIN right away in that case and let the existing "both sides closed" path drop the session. Advance myAck before calling onTcpClose so that FIN acks the guest's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TadahiroYamamura
added a commit
to TadahiroYamamura/gondolin
that referenced
this pull request
Oct 19, 2026
…FIN is acked When the guest's FIN arrived in FIN_WAIT, the session was dropped even if our FIN was still unacked (CLOSING in RFC 9293), so a retransmitted FIN or the final ACK hit no session. Drop it right away only when our FIN is already acked; otherwise leave it to the ACK handling added in the previous commit. Combined with earendil-works#159, every guest-initiated close of a connection without an upstream takes this path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A4 of #155.
Problem
Before the first payload there is no upstream socket, so when the guest closes before sending anything (
nc -z, etc.), Gondolin never sends a FIN back. The guest socket stays in FIN-WAIT-2 with no FIN even after 150s, and the natTable entry stays behind too.Fix
In this case (a graceful close with no upstream socket and no protocol determined yet), send a FIN to the guest right away. The state becomes
FIN_WAIT, so the existing "both sides closed" path removes the session. So that the FIN we send ACKs the guest's FIN, advancingmyAckwhen the guest's FIN is accepted now happens beforeonTcpCloseis called.Tests
On both the HTTP path and the mapped TCP path, a guest FIN before any payload gets exactly one FIN back (with the right seq and ack), and natTable and tcpSessions end up empty. A guest RST before any payload gets no reply.
Please check
onTcpClosecallback intohandleTcpEnd. This is the same pattern as the existinghandleTcpConnectcallinghandleTcpConnectedfrom insideonTcpConnectmyAckis now advanced first, on every path the ack number of any segment sent from insideonTcpCloseincludes the guest's FIN. All existing tests passnetwork-stack.ts). If both are merged, the correct order is "advancemyAck→guestFinReceived = true→onTcpClose"Suggested CHANGELOG entry
Fix guest TCP connections closed before sending any data never getting a FIN back, which left the guest in FIN-WAIT-2 and the session behind.
🤖 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.