Skip to content

Flush TNode output queued while connecting once the connection completes - #223

Merged
resetius merged 1 commit into
masterfrom
fix-tnode-flush-after-connect
Nov 19, 2026
Merged

resetius merged 1 commit into
masterfrom
fix-tnode-flush-after-connect

Conversation

@resetius

Copy link
Copy Markdown
Owner

Fixes #219

DoConnect() set Connected = true but never started the drainer, so bytes queued while the node was connecting (or left after a send error, which goes through Connect() too) waited for the next message to call Drain().

DoConnect() now starts the drainer when it finishes and CommittedBytes > 0. The "start the drainer if idle" logic moved from Drain() into a small StartDrain() helper shared by both.

Test: test_node_flushes_bytes_queued_while_connecting queues a message, calls Drain() once before the peer listens, then only steps the loop. It fails on master and passes with the fix.

Note: the PR for #220 adds a destructor to TNode near the constructor and this PR edits other places, so they should rebase trivially.

@github-actions

Copy link
Copy Markdown

Unit Test Results (MacOS)

255 tests  +1   255 ✅ +1   28s ⏱️ -4s
  4 suites ±0     0 💤 ±0 
  4 files   ±0     0 ❌ ±0 

Results for commit f05c217. ± Comparison against base commit 85489f0.

@github-actions

Copy link
Copy Markdown

Unit Test Results (Linux)

334 tests  +1   334 ✅ +1   24s ⏱️ -1s
  4 suites ±0     0 💤 ±0 
  4 files   ±0     0 ❌ ±0 

Results for commit f05c217. ± Comparison against base commit 85489f0.

@github-actions

Copy link
Copy Markdown

Unit Test Results (Windows)

176 tests  +1   176 ✅ +1   44s ⏱️ ±0s
  4 suites ±0     0 💤 ±0 
  4 files   ±0     0 ❌ ±0 

Results for commit f05c217. ± Comparison against base commit 85489f0.

@resetius

Copy link
Copy Markdown
Owner Author

Independent review of head f05c217522a1ed67a482c6ea964ca955205c3182. Verdict: the fix is correct. No P1/P2 findings, one P3 note.

What I checked

  • TNode does not send messages queued while it connects until another message is queued #219 and the diff. When the connect loop ends, DoConnect() now calls StartDrain() if CommittedBytes > 0 (coroio/actors/node.hpp:185-188). StartDrain() keeps the old guard: the node must be Connected and no drainer may be running. So only one drainer exists at a time, and no bytes are sent twice.
  • Wake-up paths.
    • Connect started from Drain(): that Drain() skipped draining because the node was not connected yet, and the end of DoConnect now starts the drainer.
    • Connect started from DoDrain's catch: DoConnect suspends in Connect. It always does on uring and IOCP, and on readiness pollers a TCP connect() returns EINPROGRESS. DoDrain then finishes, and the later StartDrain() replaces the finished drainer frame.
  • Order and integrity. DoDrain swaps the buffers and zeroes CommittedBytes before each write. After a reconnect the new connection therefore starts at a message boundary. The bytes of a failed write are dropped, as on master.
  • The test fails without the fix. With master's node.hpp, the kqueue run on macOS fails at assert_true(done) (tests/test_actors.cpp:1288), and so does a local TUring variant on rpi5. With the fix it passes on kqueue, poll and select (macOS) and on epoll, uring and poll (Linux, poller switched locally).
  • Full ctest with ASan on macOS and on rpi5 (Linux 7.3): all passed. CI: every job on this head is green.

Findings

@resetius resetius added the agent-reviewed An independent review agent checked this PR; the verdict is in a PR comment label Nov 19, 2026
@resetius
resetius merged commit 4803d2c into master Nov 19, 2026
7 checks passed
@resetius
resetius deleted the fix-tnode-flush-after-connect branch November 19, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed An independent review agent checked this PR; the verdict is in a PR comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TNode does not send messages queued while it connects until another message is queued

1 participant