Repository navigation
Fix race condition in ctx_t::send_command during concurrent socket destruction - #4936
Open
Tyagiquamar wants to merge 2 commits into
Open
Tyagiquamar wants to merge 2 commits into
Tyagiquamar wants to merge 2 commits into
Conversation
Solution: compare the slot with NULL before applying the branch hint
Author
|
The failing Linux build passes a mailbox pointer to __builtin_expect through likely(slots[tid]). GCC requires an integer expression there. Changed it to likely(slots[tid] != NULL), preserving the slot lock and the null-slot behavior. Reproduced the compiler error in Docker before the change. Ubuntu 24.04/GCC 13.3.0: library and three focused test binaries built; shutdown stress (1 case), context destruction/shutdown (9 cases), and endpoint termination (4 cases) passed. Clang-format 18.1.8 checked the changed function, and git diff --check passed. No full suite was run. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In \ctx_t::send_command(tid_, command_), _slots[tid_]\ is dereferenced to dispatch commands to mailboxes without holding _slot_sync.
Concurrently, when a socket is destroyed in \socket_base_t::check_destroy()\ -> \ctx_t::destroy_socket(), the reaper thread locks _slot_sync, clears _slots[tid] = NULL, and proceeds to delete the socket object and its embedded \mailbox_t.
When IO threads or peer sockets concurrently send routing commands (such as \ erm-ack, unbind, or pipe termination signals) to a socket undergoing destruction:
Solution
**Synchronize slot access in \ctx_t::send_command**:
Prevent recursive mutex deadlock during reaper termination:
Fixes #4926.