`gio open URL` terminates too quickly in rare corner case
This is a huge shot in the dark but perhaps someone might be able to help.
I'm the maintainer of host-spawn (https://github.com/1player/host-spawn), an alternative to flatpak-spawn --host
. The only real difference between this and flatpak-spawn
is that we allocate a pty for the child process to deal with a number of issues.
host-spawn works great except in one single case: when trying to spawn a browser with gio open URL
. Invoked as host-spawn gio open http://google.com
I can see Firefox being spawned in the log:
Started app-glib-org.mozilla.firefox-28359.scope - Application launched by gio open.
but a successful invocation, i.e. flatpak-spawn --host gio open http://google.com
shows:
Started app-glib-org.mozilla.firefox-28359.scope - Application launched by gio open.
Started app-flatpak-org.mozilla.firefox-28359.scope.
It looks like for some reason gio open URL
terminates too quickly and the second scope (also spawned via DBus) never has a chance to be executed.
The reason why I think this might be a GLib issue is that if I keep gio open
alive after launching the process (by literally duplicating this line https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/gio-tool-open.c#L133), everything works as intended.
Additionally, running gio through strace --follow-forks
, which slows down the logic considerably, fixes the issue, so I'm pretty sure it's a timing problem.
Downstream bug: https://github.com/1player/host-spawn/issues/7
EDIT to summarise a few hours of debugging: what's going on is that we allocate a pty for gio
, and gio open URL
terminates too quickly while it's still spawning the web browser. On our side we are told gio
has terminated, close the pty fd, causing the kernel to send a SIGHUP before the browser process has had a chance to spawn.
The gio tool should wait until the browser process has been started and detached before returning.