Skip to content

Fix send-failure callbacks racing message delivery - #635

Merged
bsergean merged 3 commits into
masterfrom
fix/send-failure-callback-order
Nov 5, 2026
Merged

bsergean merged 3 commits into
masterfrom
fix/send-failure-callback-order

Conversation

@bsergean

@bsergean bsergean commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

A failed send currently invokes Close on the sending thread while the connection thread may still be inside a Message callback. This can overlap callbacks and deliver messages after Close.

Use the existing close path: fatal writes, write-readiness errors, and send timeouts call close(1006, reason). An abnormal close discards pending output and wakes the connection thread without sending a Close frame. The active Message callback finishes; further buffered data callbacks are suppressed while CLOSING, as with an explicit close. The connection thread closes the socket and delivers the final Close callback. CLOSED is published before the callback so reentrant close() is safe.

This uses the existing state, close code, and close reason, with no additional member variables. The first close request retains its code/reason, and timeout/cancellation behavior remains covered by tests. Production code remains C++11 compatible.

Closes #551.

Validation:

  • Full OpenSSL suite: 25/25 passing. Full Mbed TLS suite: 26/26 passing.
  • Regression covers client/server failures, write-readiness errors, timeouts, callback ordering/thread, reentrant close(), cancellation, close before connecting, and reconnect. It passes under ThreadSanitizer.
  • Reporter’s server under ThreadSanitizer with 20 abrupt disconnects during bidirectional traffic: passing.
  • Targeted Autobahn: 51/51 cases passing in each role. Full compliance requested through the autobahn label.

@bsergean bsergean added the autobahn Run the Docker Autobahn client and server compliance check label Nov 5, 2026
@bsergean
bsergean merged commit ac84ac8 into master Nov 5, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autobahn Run the Docker Autobahn client and server compliance check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Callbacks for Message after Close if sending fails

1 participant