Repository navigation
Conversation
`frida_deinit()` blocks after a local attach: `gio_shutdown()` joins the shared GDBus worker thread, and that worker exits only once the last `GDBusConnection` object is finalized. A connection can outlive its session — after attaching to this process the agent's connection keeps one reference that nothing in frida's own bookkeeping releases — so the join never returns and the host hangs in a teardown call that is supposed to finish. Measured on macOS arm64 at 17.27.5 and 17.28.0 alike: `frida-core-example` attaching to itself, and a three-line host that creates a manager, attaches to pid 0, loads a script and tears everything down, both block in `_g_dbus_shutdown` forever. The agent's own environment deinit completes; the block is the host's. Wait for the shutdown, but not forever: it runs on its own thread and the caller gives up after five seconds, leaving the thread to the process. `gio_deinit()` later runs the same shutdown, so it is skipped in that case. With this, both harnesses print `deinit returned` and exit 0; the reporter that a connection is still referenced is a separate question from a teardown that can hang forever.
|
Closing this: the root cause is found, and this workaround is no longer wanted. The connection that kept GLib's D-Bus worker alive was idun's, not frida-core's: The real fix is frida/idun#13: close that connection on the failure path. Verified on macOS here: with it, frida-core will pick it up by bumping |
27da923 to
80edc2a
Compare
80edc2a to
27da923
Compare
|
Closing this — the root cause is found and the real fix is #1308 (with the origin in frida/idun#14), so the bounded shutdown is not needed. What the workaround was hiding: Thanks to everyone who looked at it. |
This is a workaround. It makes
frida_deinit()return; it does not identify or release the reference that keeps GLib's D-Bus worker alive.The hang
frida_deinit()→gio_shutdown()joins the shared GDBus worker thread, and that worker exits only when the lastGDBusConnectionobject is finalized. After a local attach one connection never finalizes, so the join never returns.Reproduced on macOS arm64 at 17.27.5 and 17.28.0 alike (not a regression of this release), with a three-line host (
DeviceManager::new()→ local device →attach(0)→create_script("1;")→ load → detach →close()→frida_deinit()) and with frida's ownfrida-core-exampleattaching to itself.What the reference hunt produced
An lldb breakpoint on
g_object_ref/g_object_unref, filtered toGDBusConnectionby checking the object'sGTypefrom a Python callback, logs every reference with its call site:That idun leak is real and fixed separately in frida/idun#13 — but it is not this hang: measured with that fix and no other change, the host still blocks in
frida_deinit().What this change does
GLib's shutdown runs on its own thread; the caller waits five seconds, and if it has not finished, gives up and skips
gio_deinit(), which runs the very same shutdown.Cost, stated plainly: one thread left behind at process exit, and a half-shut-down GLib in that process. It is a safety net for a teardown that must return, not a fix.
What a real fix needs
Find the remaining unaccounted reference — the idun one is removed, so it is something else (the agent's connection balances, its entry is finalized, and its
closedhandler never runs) — and release it, after which GLib's shutdown completes normally. I am happy for this PR to be rejected if carrying a workaround is worse than carrying the hang.