kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

kolibri-daemon hangs instead of exiting when it cannot claim its D-Bus name

Open dylanmccall opened this issue 3 years ago • 4 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

When kolibri-daemon cannot claim its D-Bus name, it prints Failed to register: Unable to acquire bus name and then hangs instead of exiting.

Complexity: Low Target branch: develop

Context

  • Application.__init__ calls self.hold() (application.py#L413-L415), which is released only when Kolibri attaches.
  • A failed registration never attaches Kolibri, so g_application_run() keeps iterating on the held use count and never returns.
  • main() blocks in await_bus_name(), which returns only when run() does.
  • GApplication emits startup only on the primary instance, after registration succeeds (do_startup).

The Change

  • Take the initial hold in do_startup instead of __init__, so a failed registration lets run() return.

How to Get There

  1. Install the Devel flatpak.
  2. Start a private session bus: dbus-run-session -- sh.
  3. Hold the daemon's name: flatpak run --command=python3 org.learningequality.Kolibri.Devel -c "from gi.repository import Gio, GLib; Gio.bus_own_name(Gio.BusType.SESSION, 'org.learningequality.Kolibri.Devel.Daemon', 0, None, None, None); GLib.MainLoop().run()" &
  4. Run flatpak run --command=/app/libexec/kolibri-app/kolibri-daemon org.learningequality.Kolibri.Devel --session: it prints Failed to register and does not exit.

Acceptance Criteria

  • [ ] When the daemon cannot claim its D-Bus name, it exits non-zero with no Kolibri process left running.
  • [ ] First launch after an upgrade that runs migrations still shows the loading page, with no inactivity-timeout exit.
  • [ ] kolibri_daemon_tests cover run() returning when the bus name is already owned.

AI usage

Claude Code reproduced the hang on a local build of #15349 and located it from a Python faulthandler stack dump.

dylanmccall avatar Aug 26 '23 00:08 dylanmccall

There was an attempt to solve this in learningequality/kolibri-installer-gnome#77, but it broke some other things and needed to be reverted.

dylanmccall avatar Aug 26 '23 00:08 dylanmccall

Fixed by #15349: the daemon now starts Kolibri only after it owns its bus name. kolibri-daemon --help on a build of that PR prints help, exits 0, and leaves no daemon process running.

rtibbles avatar Sep 25 '26 16:09 rtibbles

Reopening: #15349 fixed --help, but a daemon that cannot claim its bus name still hangs after Failed to register. Issue rewritten to cover that.

rtibbles avatar Sep 25 '26 16:09 rtibbles

Plan: A kolibri-daemon that cannot claim its D-Bus name returns from run() with a non-zero status instead of hanging.

  • [ ] Take the startup hold in do_startup
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • --system name loss already quits (exit 0, no hang) and stays unchanged, since only --session ships; if AC1 covers --system, main() needs a non-zero status there.
  • AC2 is checked by a unit test plus CI's smoke test, not a manual upgrade run; if one is required, it needs a host where flatpak runs, which this sandbox refused while planning.

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Sep 25 '26 17:09 rtibblesbot