8000 subprojects: release idun's backends when its monitor stops by kkuehl · Pull Request #1308 · frida/frida-core · GitHub
[go: up one dir, main page]

Skip to content

subprojects: release idun's backends when its monitor stops - #1308

Closed
kkuehl wants to merge 1 commit into
frida:mainfrom
kkuehl:kkuehl/idun-release-backends
Closed

kkuehl wants to merge 1 commit into
frida:mainfrom
kkuehl:kkuehl/idun-release-backends

Conversation

@kkuehl
@kkuehl kkuehl commented Nov 27, 2026
Copy link
Copy Markdown
Contributor

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

main thread   frida_deinit → gio_shutdown → _g_dbus_shutdown → g_cond_wait
gdbus thread  g_main_loop_run (still polling)

_g_dbus_shutdown() waits while gdbus_workers is non-empty. A worker leaves that list only when its last reference goes, and a worker's last reference is the GDBusConnection that 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:

idun_daemon_client_try_open_endpoint_co    daemon-client.vala:94

(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 in backends. The daemon backend holds the DaemonClient, 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 backends once 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 as subprojects/packagefiles/idun.diff with diff_files = idun.diff in 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's revision.

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):

17.28.0                        round 0 released → blocks in frida_deinit (killed at timeout)
17.28.0 + this wrap patch      round 0, 1, 2 released → deinit returned → exit 0 (3.4 s)

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.)

`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()`.
@kkuehl
kkuehl commented Nov 27, 2026
Copy link
Copy Markdown
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 DeviceMonitor.stop() — and once it is in, the only change frida-core needs is the subprojects/idun.wrap revision bump, which I will send as a follow-up PR then.

Nothing here is lost by closing it: the diagnosis in this body is what pointed at idun, and it holds either way —

main thread   frida_deinit → gio_shutdown → _g_dbus_shutdown → g_cond_wait
at the breakpoint: one worker left, created by idun_daemon_client_try_open_endpoint_co
cause: DeviceMonitor.stop() keeps the backends, and with them the DaemonClient
       and the D-Bus connection that keeps the worker alive

If you would rather not wait for an idun release, the alternative is the third option above — drop the monitor in FruityHostSessionBackend.stop() — and I can open that instead on request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0