Connect/disconnect unrelated interface plug breaks GTK 3 app

Hello, could someone confirm this behavior is expected? I was really confused at first, but then I think I figured it out.

I am working on a snap that uses core20 + the gnome-3-38 extension. It has a GTK3 GUI front end app (Python + PyGObject) that works really well, except when I manually connect or disconnect a plug (such as mpris) unrelated to desktop/GUI operations, while the GUI app is running. When I do this, bad things happen: Fonts and icons go missing and some asserts get triggered in GTK, resulting in the app crashing at times. I suspect this happens because of security profiles being re-applied when the snap interface plug gets connected/disconnected (it seems like locations get remounted and are no longer accessible until the app is relaunched). This effect is similar to refreshing the snap while the app is running.

I decided to avoid this mess by making the GUI app monitor a file in SNAP_COMMON and quit itself after posting an informative desktop notification, whenever this file changes. I have snap hooks set up to touch this file whenever certain plugs are connected or disconnected, as well as when the snap is refreshed. For me it’s unacceptable to see a GUI app get disfigured or crashed when a manual plug unrelated to desktop/GUI operations is manually connected/disconnected while the app is running.

I realize this is kind of an edge case, but this is my main problem: The snap requires the mpris interface, and so the GUI front end uses snapctl to check if the mpris plug is connected, giving the user instructions on how to connect it manually if necessary. Once the user manually connects it, the (still running) GUI app starts to have the issues I described.

Anyway, I am wondering if I am missing something and if what I described above is a reasonable workaround. Please let me know if you have a better idea. Having the GUI app self-quit with a desktop notification in this case is OK IMO, because it’s just a front end management tool for a service.

Your diagnosis is spot on. Some interfaces are disruptive in that regard, i.e. may create new mountpoints and affect namespaces (content interface is one of them), and this may confuse apps up to the point where they crash.

I think your workaround is reasonable. Maybe it can be simplified by only using snapctl is-connected on app startup and refuse to start if not connected (with a hint for the user), then the user needs to connect fist before running the app. I’d consider the ‘disconnect’ case less of a problem, because if you disconnect a plug of an app while it’s running, you most likely (as a user) know what you’re doing, and should expect unexpected…

1 Like

Thank you, that’s helpful.