Repository navigation
Conversation
When closing a socket, a pending read might want to set the socket state to LostConnection. This commit only goes to LostConnection if the current state is Connected. This better reflects the socket state machine.
|
Current version of PR was reviewed by /review-bugbot on Oct 12, 12:50. It flagged 4 findings. Show 4 findings1. Local benchmark CSV committed
A new ~15,000-line CSV named after a private LAN address ( 2. Machine-specific compile database committed
A 3. Heaptrack profiles committed
Binary heaptrack profile archives for 4. Playbook contradicts package install flag
The playbook header states it runs without sudo because Bugbot on commit |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #593 +/- ##
==========================================
+ Coverage 83.27% 83.90% +0.62%
==========================================
Files 126 126
Lines 8168 8250 +82
Branches 3757 3804 +47
==========================================
+ Hits 6802 6922 +120
+ Misses 955 915 -40
- Partials 411 413 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
🟡 Changes recommended
A stale read can still mark a newly reconnected socket as LostConnection.
1 open finding
What changed in this PR
Prevents deliberate socket closure from being reported as a lost connection.
Changes:
- Uses compare-and-exchange before setting
LostConnection. - Adds a concurrent disconnect/read regression test.
| File | Description |
|---|---|
src/comm/tcp_socket.cpp |
Conditionally transitions connected sockets to LostConnection. |
tests/test_tcp_socket.cpp |
Tests disconnecting during a pending read. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
5131f1f to
afa517d
Compare
| setTargetStateUnlessStopRequested(SocketState::Connected); | ||
| if (!setupInternal(host, port, max_num_tries, reconnection_time)) | ||
| StateGeneration connection_attempt; | ||
| if (!setupInternal(host, port, max_num_tries, reconnection_time, connection_attempt)) |
| EXPECT_NO_THROW(waitFor([&read_started]() { return read_started.load(); }, std::chrono::seconds(1))); | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(50)); |
| // Only the exact connection on which recv() started may be marked lost. A concurrent close() | ||
| // changes the state, and a reconnect changes the generation, so neither can be overwritten by | ||
| // this read's stale result. | ||
| StateGeneration expected = read_state; | ||
| state_generation_.compare_exchange_strong(expected, makeStateGeneration(SocketState::LostConnection, read_state)); |


When closing a socket, a pending read might want to set the socket state to LostConnection. This commit only goes to LostConnection if the current state is Connected. This better reflects the socket state machine.
This came up when reviewing #588.