In xdg-desktop-portal#241, it was proposed to expose GSettings (i.e. dconf) via a portal. Instead, GSetting’s “keyfile” backend was used to store an INI file in the Flatpak’s private directory and that’s that. inotify is used to monitor the file for changes.
Quick look at KDE’s kconfig seems to indicate that they use something very similar, but I’m unsure how notifications work. Seems like whenever a client changes a config file, it anonymously broadcasts onto the session bus that “I just changed these settings paths: …” and that’s about it. I didn’t even know dbus supports something like that, and it’s unclear to me whether or not that would work through the Flatpak sandbox.
The problem with our approach is inotify. The kernel, by hard-coded default, only allows 128 individual inotify connections per user. Ultimately, this means that having 128 processes inside of some Flatpak containers that use GSettings, will exhasut the user’s inotify resources.
You can actually hit this 128 process limit quite easily by opening many tabs in Epiphany. Each web worker process (and thus tab) makes a GSettings connection, which of course inside of a Flatpak means using inotify, which means if you have ~128 tabs open in Epiphany the resource is exhausted. Related: inotify usage is way too high, Epiphany crashes after opening ~75 tabs (#1454) · Issues · GNOME / Epiphany · GitLab.
This eventually leads to full session crashes: gnome-software will install a system update, which causes dbus-broker to try and relaunch itself, which fails because it cannot set up inotify watches it needs, which means that there’s no session bus anymore, which rapidly brings down GNOME-shell and the entire rest of the session.
So, ideas on how to best solve this would be appreciated. I’ve yet to come up with anything better than just bumping the limit in the kernel (or maybe make systemd tune the value by default? Or make it a per-distro change?), but I don’t know the repercussions of that. If anyone has alternative ideas I’m all ears!