Repository navigation
agent: Fix pending-call underflow on disconnect - #1300
Merged
Merged
Conversation
GDBus runs outgoing filters on its worker thread as it writes each message, so a reply queued before the peer vanished can pass through our filter after on_connection_closed() has reset pending_calls to zero. The counter then wraps, and perform_unload() waits forever for calls that will never complete, hanging the agent's thread. Stop counting replies once the connection is closed. The worker sets the closed flag before scheduling the closed signal, and runs filters on the same thread, so no decrement can land after the reset.
oleavr
force-pushed
the
fix/agent-pending-calls-underflow
branch
from
November 23, 2026 15:24
3d1a1e4 to
ab3b196
Compare
Member
|
Thanks! 🙌 |
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.
Closing a
DeviceManageroccasionally hangs the whole process (macOS). The in-process agent's worker thread never exits, soAgentContainer.destroy()blocks frida-core's only message-loop thread forever instop_worker_thread()'sthread.join(), and every later sync call also waits.Cause
The agent's
pending_callscounter tracks incoming method calls that expect a reply; each outgoingMETHOD_RETURN/ERRORdecrements it, from a GDBus filter. GDBus runs outgoing filters on its worker thread as it writes each message, not when the reply is sent. So a reply that was queued before the peer vanished can pass through the filter afteron_connection_closed()has resetpending_callsto zero on the agent's thread. The unsigned counter then wraps,perform_unload()waits onpending_closefor calls that will never complete, never schedulesmain_loop.quit(), and the worker never exits.Fix
Stop counting replies once the connection is closed. GDBus sets the closed flag on its worker thread before scheduling the
closedsignal, and runs filters on that same thread, so after the flag is set no decrement can happen, and every earlier one happens before the reset. The counter stays exact, rather than being clamped at zero.Reproduction / verification
The hang is a rare (~1%) concurrency race that needs several concurrent
frida-coreclients repeatedly creating and closing a manager. With the frida-rustgirtest binary run 4-up, 300-run batches:main(17.27.4): 3 hangs (reproduced on both the released devkit and a local build)The branch has since been rewritten to fix the race itself instead of clamping the counter. @kkuehl, could you re-run your batches against the new revision?