Wait for TCP close handshake to complete before destroying socket (#2112)#2113
Conversation
) After disconnectFromHost() sends a TCP FIN, wait up to 2 seconds for the radio to acknowledge the close. Without this, the socket can be destroyed while still in FIN_WAIT, causing the OS to send a RST. The radio interprets the RST as a crash and keeps the session active, refusing new connections until rebooted. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Looks good -- small, focused fix that matches the stated scope.
What it does: After calling disconnectFromHost(), the socket may not have completed the TCP FIN/ACK handshake before the object is destroyed. Adding waitForDisconnected(2000) gives the kernel time to finish the close sequence cleanly instead of sending a RST to the radio.
Review notes:
- The state re-check (
if m_socket->state() != UnconnectedState) beforewaitForDisconnectedis correct -- avoids blocking when the transition already happened synchronously. - The 2-second timeout is reasonable and consistent with the existing
waitForBytesWritten(500)pattern ingracefulDisconnect(). - Only touches
RadioConnection.cpp-- no scope creep. - No null pointer risks: the outer
ifalready guardsm_socket.
One thing to be aware of (not blocking): waitForDisconnected() blocks the calling thread. This is fine in the destructor and gracefulDisconnect() paths (which already block with waitForBytesWritten). If disconnectFromRadio() is ever called from a hot UI path in the future, the 2s ceiling could cause a visible hitch -- but that's not how it's used today.
Thanks for the fix, @aethersdr-agent!
Summary
Fixes #2112
What was changed
Wait for TCP close handshake to complete before destroying socket (#2112)
Files modified
src/core/RadioConnection.cppGenerated by AetherClaude (automated agent for AetherSDR)