Repository navigation
Conversation
`frida_deinit()` blocks after a local attach, whenever idund is running. The chain is: gio_shutdown() → _g_dbus_shutdown() waits while `gdbus_workers` is non-empty; a worker's last reference is the `GDBusConnection` that created it; and the daemon backend's client keeps its connection alive because `DeviceMonitor.stop()` stops the backends but never releases them. So the monitor closes its client's connection and then keeps the client that owns it, the connection is never finalized, the worker never leaves the list, and the wait never returns. Measured at `_g_dbus_shutdown`: exactly one worker left, created by `idun_daemon_client_try_open_endpoint_co`. The fix is in idun, and it is open there as frida/idun#14: clear the backends once all the stops have completed. Nothing reads a stopped monitor's backends — it cannot be restarted. Carried here as a wrap patch until idun has it: three rounds of new DeviceManager → local device → attach(0) → script → detach → close now print `deinit returned` and exit 0 in 3.4 s, with GLib's shutdown completing normally — no bounded wait, no skipped `gio_deinit()`.
Contributor
Author
|
Closing this: a wrap patch is a temporary workaround, and the fix belongs in idun where the leak is. frida/idun#14 is that fix — one statement in Nothing here is lost by closing it: the diagnosis in this body is what pointed at idun, and it holds either way — If you would rather not wait for an idun release, the alternative is the third option above — drop the monitor in |
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.
frida_deinit()blocks after a local attach whenever idund is running. Fixed at the source in frida/idun#14; carried here as a wrap patch until idun has it.Where the block is
_g_dbus_shutdown()waits whilegdbus_workersis non-empty. A worker leaves that list only when its last reference goes, and a worker's last reference is theGDBusConnectionthat created it. So the shutdown blocks until every connection has been finalized — closed is not enough.At that breakpoint exactly one worker was left, created here:
(The other connection — the agent's — balances and goes away.)
Bisecting the backend confirms the neighbourhood: built with
-Dfruity_backend=disabled,frida_deinit()returns immediately; with it on, it blocks.Why the connection outlives everything
DeviceMonitor.stop()stops each backend and closes the devices, but leaves the backends inbackends. The daemon backend holds theDaemonClient, the client holds the connection: stopping the monitor even closes that connection, and then keeps the client that owns it, so the connection object is never finalized and its worker never leaves the list.The fix
In idun: clear
backendsonce all the stops have completed. Nothing reads a stopped monitor's backends —start()refuses once it is stopped.frida-core pulls idun as a meson wrap (
subprojects/idun.wrap→frida/idun@1fd0cfe), so the change arrives here assubprojects/packagefiles/idun.diffwithdiff_files = idun.diffin the wrap — meson's mechanism for a dependency fix that has not been released. When idun#14 lands this is replaced by bumping the wrap'srevision.Checked
macOS arm64, three rounds of
DeviceManager → local device → attach(0) → create_script("1;") → load → detach → close(self-attach, so agent and helper are exercised):GLib's shutdown completes normally — no bounded wait, no skipped
gio_deinit(). The same single-round host, run three times, exits 0 each time.(The multi-round run also needs #1306; on plain 17.28.0 round 1 dies in the agent, which is that bug and not this one.)