desktop icon indicating copy to clipboard operation
desktop copied to clipboard

[Bug] [Flatpak] Stale KDSingleApplication lock file prevents launch after logout/login

Open Aqua1ung opened this issue 8 months ago • 15 comments

Component: Nextcloud Desktop (Flatpak)

Version: 33.0.0daily (Flatpak)

OS: blendOS (Arch Linux), GNOME/Wayland

Description

After a logout/login cycle (not a reboot), the Nextcloud Desktop Flatpak client fails to start. The app immediately exits with status 255, logging "Already running, exiting...".

The cause is a stale lock file at:

~/.var/app/com.nextcloud.desktopclient.nextcloud/cache/tmp/kdsingleapp-dad-nextcloud.lock

KDSingleApplication creates this lock to enforce single-instance behavior, but it is not cleaned up when the session ends via logout. On the next login, the new instance finds the lock file, assumes another instance is running, and exits.

Steps to reproduce

  1. Launch Nextcloud Desktop (Flatpak) — it runs normally
  2. Log out of the GNOME session
  3. Log back in
  4. Nextcloud Desktop fails to start (autostart or manual launch)

Journal output

nextcloud.gui.application: Already running, exiting...
dbus-:[email protected]: Main process exited, code=exited, status=255/EXCEPTION

Workaround

rm ~/.var/app/com.nextcloud.desktopclient.nextcloud/cache/tmp/kdsingleapp-dad-nextcloud.lock

Expected behavior

KDSingleApplication should detect stale locks — for example by using flock() (which auto-releases when the process dies) or by recording the PID in the lock file and checking if it's still alive. Alternatively, Nextcloud could register a cleanup handler for SIGTERM/session-end signals.

Additional context

This likely happens because the Flatpak sandbox receives SIGKILL during logout before the app has time to clean up, or because SIGTERM isn't properly forwarded through the Flatpak/systemd scope. The issue does not occur after a full reboot (since /run/user/ or $XDG_CACHE_HOME/tmp gets wiped).

A secondary issue is that config migration from data/Nextcloud to config/Nextcloud also fails repeatedly for sync log files that exist in both locations, producing log noise on every launch.

File against

Aqua1ung avatar Apr 04 '26 18:04 Aqua1ung

I have the same issue but on MacOS. I believe I have found the folder where it should be (/var/folders/st/.../T/com.nextcloud.desktopclient/), but I am unable to ls or rm -r it, even when super user (Operation not permitted). This means that the nextcloud app is entirely unable to launch. For me it happened due to a crash

jubiman avatar Apr 06 '26 12:04 jubiman

@jubiman Are you referring to #9694? I opened KDAB/KDSingleApplication#115 which is a different root cause, though (too long path for UNIX socket).

i2h3 avatar Apr 10 '26 12:04 i2h3

That is very possible. When I launch Nextcloud through the terminal I get the following output:

/Applications/Nextcloud.app/Contents/MacOS/Nextcloud 
KDSingleApplication: unable to make the primary instance listen on kdsingleapp-501-Nextcloud: QLocalServer::listen: Unknown error 1
nextcloud.sync.configfile: Default update channel is "stable"
nextcloud.gui.application: Already running, exiting...
kdsingleapplication.localsocket: Connection timed out

Though, it is running macOS 13.7.8, meaning it is entirely possible that the crash did not cause this issue, but that I am having trouble with #9694.

jubiman avatar Apr 10 '26 14:04 jubiman

Hi, I have the same issue on flatpak version 33.0.2 using Bazzite with GNOME/Wayland. The only difference is that it doesn't launch even after a fresh start of my computer, when I launch it via CLI, I get this :

me@bazzite:~$ flatpak run com.nextcloud.desktopclient.nextcloud
nextcloud.gui.application: Migrating old config from "/home/me/.var/app/com.nextcloud.desktopclient.nextcloud/data/Nextcloud" to "/home/me/.var/app/com.nextcloud.desktopclient.nextcloud/config/Nextcloud"
nextcloud.gui.application: Failed to move the old config directory to its new location ( "/home/me/.var/app/com.nextcloud.desktopclient.nextcloud/data/Nextcloud" to "/home/me/.var/app/com.nextcloud.desktopclient.nextcloud/config/Nextcloud" )
nextcloud.gui.application: Will move the individual files QList("Nextcloud_sync.log")
nextcloud.gui.application: Fallback move of  "Nextcloud_sync.log" also failed
nextcloud.gui.application: Already running, exiting...
kdsingleapplication.localsocket: Connection timed out

Also I can't exec rm ~/.var/app/com.nextcloud.desktopclient.nextcloud/cache/tmp/kdsingleapp-dad-nextcloud.lock because the file does not exist :

rm ~/.var/app/com.nextcloud.desktopclient.nextcloud/cache/tmp/kdsingleapp-dad-nextcloud.lock
rm: impossible de supprimer '/home/me/.var/app/com.nextcloud.desktopclient.nextcloud/cache/tmp/kdsingleapp-dad-nextcloud.lock': Aucun fichier ou dossier de ce nom

It means I can't open the client at all

(After some research it appears my problems is mixed with #6201)

RobinBouvier avatar Apr 13 '26 16:04 RobinBouvier

Hi, I have the same issue on flatpak version 33.0.2 using Bazzite with GNOME/Wayland. The only difference is that it doesn't launch even after a fresh start of my computer, when I launch it via CLI, I get this

You need to remove that file. Replace dad with your user name.

Aqua1ung avatar Apr 13 '26 16:04 Aqua1ung

Hi, I have the same issue on flatpak version 33.0.2 using Bazzite with GNOME/Wayland. The only difference is that it doesn't launch even after a fresh start of my computer, when I launch it via CLI, I get this

You need to remove that file. Replace dad with your user name.

Yeah it worked ! Thank you I'm sorry, I should look better at answers...

RobinBouvier avatar Apr 13 '26 19:04 RobinBouvier

Alternatively, Nextcloud could register a cleanup handler for SIGTERM/session-end signals.

Note that this will not work in cases like mine where Linux kernel panic halted the entire machine. It is way better to use stateful locks based on flock or sockets instead, imo.

MrApplejuice avatar Apr 17 '26 10:04 MrApplejuice

I have this issue as well, on Debian 13. I've got it installed through Flatpak, currently on version 33.0.4.

Same result when I delete the lock file and restart the app manually.

I guess it might be possible to make a user-level systemd unit to delete the lock file right when you sign in before the app can start, but that's a bit of a nasty hack eh? I'd rather have a "real" fix if possible ;)

noahbailey avatar May 06 '26 20:05 noahbailey

I'm having the same problem with the Flatpak version of Nextcloud 33.0.5. I'm running Fedora 44 with KDE and Wayland. Deleting the lock file works for me, too.

Obi-Wahn avatar May 21 '26 10:05 Obi-Wahn

Same issue here. Deleting the lockfile resolved it.

  • Flatpak 33.0.5daily
  • OS: Secureblue
  • DE: Gnome

ralf401 avatar May 21 '26 17:05 ralf401

GNOME 50.2 - Fedora Silverblue Nextcloud Desktop Client Flatpak com.nextcloud.desktopclient.nextcloud 33.0.5 stable system

flatpak run com.nextcloud.desktopclient.nextcloud 
nextcloud.gui.application: Already running, exiting...
kdsingleapplication.localsocket: Connection timed out

fixed by clearing tmp cache as described above

rm -rf .var/app/com.nextcloud.desktopclient.nextcloud/cache/tmp

CodingKoalaGeneral avatar Jun 18 '26 07:06 CodingKoalaGeneral

Suddenly, for reasons I can't quite pinpoint, the tmp folder is deleted when I exit the Nextcloud client. Starting the Nextcloud client (33.0.5daily and flathub on Fedora 44 KDE) is working at the moment.

Obi-Wahn avatar Jun 20 '26 15:06 Obi-Wahn

for your info, https://github.com/nextcloud/desktop/pull/10088 has been merged for 34.0.x should make it works better agnostic of the package format only requires a DBus session bus

mgallien avatar Jun 22 '26 10:06 mgallien

should have been closed with #10088

mgallien avatar Jul 20 '26 09:07 mgallien

Still happening on 33.0.3daily (Flathub, Ubuntu 26.04, GNOME/Wayland), so whatever #10088 fixed hasn't reached the 33.x branch.

One detail I haven't seen mentioned: the .lock records PID 2 (the process ID as seen inside the Flatpak sandbox) while the hostname field holds the host's name. So a "is that PID still alive?" check run from a new sandbox always answers yes, and the lock never expires. Worth confirming #10088 doesn't rely on a PID check.

Also: at least here the app is not SIGKILLed at logout. The scope stops cleanly (Stopping / Stopped, no kill in the journal) and the lock is still left behind, while --quit removes it properly.

Rather than deleting the lock by hand each time, I point the autostart .desktop at a wrapper that clears it only when nothing is running:

APP="com.nextcloud.desktopclient.nextcloud"
LOCK_BASE="$HOME/.var/app/$APP/cache/tmp/kdsingleapp-$USER-nextcloud"

pgrep -x nextcloud > /dev/null && exit 0
rm -f "$LOCK_BASE" "$LOCK_BASE.lock"
exec flatpak run "$APP" --background

Three logout/login cycles, a stale lock found every time.

Is #10088 coming to a 33.x maintenance release, or is 34.0.x the only way out? Asking because 33.0.5–33.0.7 are affected by #10297, so staying on 33.0.3 with the wrapper looks like the safer option for now, I think.

nickth76 avatar Oct 04 '26 20:10 nickth76