Fix lock order inversion in ioqueue write and connect callbacks#4806
Merged
Fix lock order inversion in ioqueue write and connect callbacks#4806
Conversation
…eue_winnt.c Co-authored-by: sauwming <[email protected]>
…lbacks Co-authored-by: sauwming <[email protected]>
Copilot
AI
changed the title
[WIP] Fix lock order inversion issue in ioqueue
Fix lock order inversion in ioqueue write callbacks
Feb 19, 2026
Member
|
@copilot: modify |
…on_abs and remove tsan suppression Co-authored-by: sauwming <[email protected]>
Contributor
Author
Member
|
@copilot: Do not hold ioq lock before calling |
…mon_abs Co-authored-by: sauwming <[email protected]>
Contributor
Author
Copilot
AI
changed the title
Fix lock order inversion in ioqueue write callbacks
Fix lock order inversion in ioqueue write and connect callbacks
Feb 19, 2026
Member
|
Using the mechanism of So we have three options:
|
Member
I agree this is the riskiest of the three approaches, given the rather aggressive changes involved. |
Member
|
Now connect and write cb can be called at the same time, similar to accept and read. |
nanangizz
approved these changes
Feb 19, 2026
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.
Description
Lock order inversion detected by TSan: ioqueue key lock (M1) acquired while holding grp_lock (M0) in one path, reversed in callback chains. Extended existing
PJ_IOQUEUE_CALLBACK_NO_LOCKpattern from read callbacks to both write and connect callbacks inioqueue_winnt.candioqueue_common_abs.c.Changes:
write_callback_threadandwrite_cb_listtopj_ioqueue_key_tfor write callback tracking and queuing in both Windows and common implementationsPJ_IOQUEUE_CALLBACK_NO_LOCKis enabledioqueue_dispatch_write_event_no_lock()to process queued write callbacks in both implementationscancel_all_pending_op()for Windows and key unregister for common implementationsPJ_IOQUEUE_CALLBACK_NO_LOCKdocumentation to reflect extended scope (now covers read, write, and connect callbacks)deadlock:stateless_send_transport_cbfromtests/sanitizers/tsan.suppVerification:
ioqueue_common_abs.cnow applies thePJ_IOQUEUE_CALLBACK_NO_LOCKpattern to read, write, and connect callbacksioqueue_winnt.capplies the pattern to read and write callbacks; connect callbacks already release locks before invocationMotivation and Context
Thread Sanitizer detects lock order inversion between ioqueue key lock and grp_lock during connect/write operations. This can cause deadlocks in multi-threaded scenarios. The fix applies the same re-entrancy prevention mechanism already used for read callbacks to both write and connect callbacks across all ioqueue implementations.
How Has This Been Tested?
Screenshots (if appropriate):
N/A
Types of changes
Checklist:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.