8000 nstun: bound FIN flow idle lifetime and correct FIN retransmissions by botegalucas · Pull Request #383 · google/nsjail · GitHub
[go: up one dir, main page]

Skip to content

nstun: bound FIN flow idle lifetime and correct FIN retransmissions - #383

Open
botegalucas wants to merge 7 commits into
google:masterfrom
botegalucas:fix/nstun-tcp-fin-lifecycle-382
Open

botegalucas wants to merge 7 commits into
google:masterfrom
botegalucas:fix/nstun-tcp-fin-lifecycle-382

Conversation

@botegalucas
@botegalucas botegalucas commented Nov 3, 2026 •
Copy link
Copy Markdown

Summary

This pull request addresses TCP connection lifecycle and resource retention issues identified in #382.

When nstun sends a FIN to the guest following host-side EOF, the TCP flow may remain in ESTABLISHED instead of transitioning into FIN_WAIT_1.

As a result, half-closed connections may retain the 3,600-second established timeout instead of the intended 60-second closing timeout.

The implementation also addresses retransmission timing, TCP sequence number handling, and repeated EPOLLHUP events that could interfere with idle connection cleanup.

Changes

  1. Apply the existing 60-second closing timeout once a FIN has been sent, including flows that remain in ESTABLISHED.

  2. Introduce an independent retransmission timer (last_retransmit) to prevent retransmissions from extending the connection's idle lifetime.

  3. Retransmit unacknowledged FIN packets using their original TCP sequence number without incorrectly advancing or rewinding the next sequence number.

  4. Prevent duplicate ACK handling from modifying TCP sequence tracking after FIN transmission.

  5. Use modular TCP sequence arithmetic to account for 32-bit sequence number wraparound.

  6. Improve host-side EOF handling to prevent repeated EPOLLHUP notifications from continuously refreshing connection activity.

  7. Add regression tests covering FIN timeout behavior, retransmissions, sequence numbers, and Linux EOF/HUP handling.

The patch deliberately avoids activating unfinished FIN_WAIT, CLOSING, and TIME_WAIT transition paths that could introduce additional regressions.

Validation Results

The updated implementation was compiled and tested successfully on Ubuntu Linux using GitHub Actions.

All checks in the final contributor-side validation workflow passed:

  • Full nsjail compilation: PASSED
  • Existing nstun unit tests: PASSED
  • TCP FIN lifecycle regression tests: PASSED
  • AddressSanitizer (ASan): PASSED
  • UndefinedBehaviorSanitizer (UBSan): PASSED
  • Linux EOF/HUP regression checks: PASSED
  • Docker image build: PASSED

Validation evidence:

Final Linux build, regression tests, and Docker build:

https://github.com/botegalucas/nsjail/actions/runs/41641007744

Additional Docker build validation:

https://github.com/botegalucas/nsjail/actions/runs/41640783227

The regression harness exercises extracted production TCP timer methods and Linux event handling behavior.

These results confirm successful compilation and the covered regression scenarios. A complete end-to-end TUN networking test with a real guest TCP connection has not yet been performed.

Scope and Compatibility

This is a targeted TCP connection-life 8000 cycle and resource-management correction.

It does not claim a demonstrated security vulnerability or a complete redesign of the TCP closing state machine.

The changes are intentionally limited to reducing resource retention and improving retransmission and EOF handling while preserving existing connection behavior.

Related Issue

Refs #382.

Review Status

The implementation has passed the available Linux build, unit, sanitizer, regression, and Docker checks on the contributor's fork.

The patch is ready for maintainer review. Additional integration testing or adjustments can be incorporated based on reviewer feedback.

@google-cla
google-cla Bot commented Nov 3, 2026
Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@botegalucas
botegalucas marked this pull request as ready for review November 3, 2026 13:12

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.

36C2

1 participant

0