Skip to content

fix(net): queue TCP sends before namespace polling - #2723

Merged
fslongjin merged 2 commits into
DragonOS-Community:masterfrom
fslongjin:codex/tcp-send-poll-contention
Nov 26, 2026
Merged

fslongjin merged 2 commits into
DragonOS-Community:masterfrom
fslongjin:codex/tcp-send-poll-contention

Conversation

@fslongjin

Copy link
Copy Markdown
Member

Summary

Established TCP writes queued data only after a synchronous namespace poll batch. Under contention, this delayed the first payload even when the connection had send-buffer space.

  • Admit established writes directly and publish accepted bytes to the existing namespace worker. Keep synchronous assistance on send-buffer backpressure.
  • Give queued bytes an output opportunity before an abortive close. This covers both zero linger and unread input. Stop at the existing budget, a closed peer window, or a lack of new output admission.
  • Add a loopback regression that checks response bytes arrive before ECONNRESET for both abort paths.

Validation

  • Kernel build, formatting and Clippy, and 254 targeted Dunitest and gVisor cases. This includes full-buffer polling, blocking large sends, cork, half-close, signal and reset handling.
  • The added reset-order regression passed 50 repeated runs. Two additional full-buffer cork and shutdown probes passed.
  • Local loopback stress: zero timeouts in the 500-connection send wave and zero in the two 100-connection tests with asymmetric vCPU scheduling. The respective local baselines produced 247 and 53 timeouts.
  • Real Docker firewall matrix: eight combinations across iptables-nft, native nftables, IPv4, IPv6, and both userland proxy settings.

An exploratory multi-segment abort comparison still saw a 6 KiB zero-linger short delivery in 2 of 160 trials. The baseline comparison saw 80 of 160 short deliveries. Repeated 8 KiB trials also showed timing-dependent truncation. The residual multi-segment behavior and the precise cause of the historical CI event remain open.

Related to #2324, tracking item 2324-53.

Admit established writes under the socket locks and hand accepted bytes
to the existing namespace worker. This avoids global polling and
socket notification scans on the ordinary write path. Keep protocol
assistance on the backpressure path, including a recheck before a
nonblocking send reports EAGAIN.

Give already queued data a chance to reach output before an established
close purges the send queue and emits a reset. Bound this work by the
existing poll budget and the closing socket's admission progress. Stop
when the peer window closes or output no longer advances.

Cover both zero linger and unread data at close with a loopback
regression that also verifies the resulting ECONNRESET.

Related to DragonOS-Community#2324.

Signed-off-by: longjin <longjin@dragonos.org>
@fslongjin

Copy link
Copy Markdown
Member Author

@codex review

@github-actions github-actions Bot added the Bug fix A bug is fixed in this pull request label Nov 25, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T10:09:19.511183Z 7d81cbf Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5fdc61a87

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread kernel/src/net/socket/inet/stream/io.rs Resolved
A successful corked write can leave bytes outside the smoltcp send
queue when the queue fills. Graceful close previously queued FIN and
unbound the socket immediately, so the peer could see EOF before it
received those bytes.

Serialize cork enqueue and consumption with close. Transfer the
remaining cork buffer to the existing deferred close entry and let it
queue the tail as ACKs free transport space. Queue FIN only once the
tail is in the transport queue. Abortive close and timeout still
discard the tail.

Keep poll publication outside the send locks and retain the
publish-only path for successful established writes. Add regression
coverage for both a short corked write and a backpressured send before
plain close.

Signed-off-by: longjin <longjin@dragonos.org>

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 7d81cbfbac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@fslongjin
fslongjin merged commit f6164f8 into DragonOS-Community:master Nov 26, 2026
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix A bug is fixed in this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant