Skip to content

session-helper: Lock runtime directory to prevent tmpfiles cleanup - #6754

Merged
swick merged 1 commit into
flatpak:mainfrom
swick:wip/tmpfile-cleanup-exclude
Aug 7, 2026
Merged

swick merged 1 commit into
flatpak:mainfrom
swick:wip/tmpfile-cleanup-exclude

Conversation

@swick

@swick swick commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator

systemd-tmpfiles periodically cleans /run/user, which can remove the
session helper's p11-kit socket. Once removed, all subsequent Flatpak
launches fail with "Can't find source path" until the session helper
restarts.

Take a shared flock on the .flatpak-helper directory for the lifetime
of the process. systemd-tmpfiles --clean skips directories that are
locked.

Closes: #6341

@smcv smcv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine as an easy, backportable bug-fix.

In the long term it would perhaps be better if the flatpak-session-helper held a fd to this directory open, and took a BSD flock(2) lock on it. That would mean that cleanup would be prevented if and only if the flatpak-session-helper is, in fact, still running. (But that would make little practical difference, because the flatpak-session-helper normally continues to run until the user logs out anyway.)

@smcv

smcv commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Do we know that this is actually the root cause of #6341? One of the reporters of that issue is on Debian 13, which I also use, and I couldn't find a reason why it would be doing age-based cleanup of /run/user by default...

(Not an objection to either this change or my flock(2) suggestion or both - if someone has configured tmpfiles cleanup of /run/user then we certainly do want to disable it for flatpak-session-helper. But I'm not particularly confident that the root cause has been identified.)

@swick
swick force-pushed the wip/tmpfile-cleanup-exclude branch from 7304ceb to a78befa Compare August 5, 2026 21:55
@swick

swick commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

I completely missed the file locking approach. That is indeed cleaner because it ties it to the lifetime of the helper process, so I implemented that instead. The code is still very minimal and should be backportable.

Do we know that this is actually the root cause of #6341?

Hard to know, but I don't see our code removing the files and this is definitely an issue we should fix either way. I guess we'll see if people continue to complain.

@swick swick changed the title data: Exclude session helper directory from tmpfiles cleanup session-helper: Lock runtime directory to prevent tmpfiles cleanup Aug 5, 2026
Comment thread session-helper/flatpak-session-helper.c Outdated
@smcv
smcv self-requested a review August 6, 2026 11:42
Comment thread session-helper/flatpak-session-helper.c Outdated
Comment thread session-helper/flatpak-session-helper.c Outdated
@smcv

smcv commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

systemd-tmpfiles periodically cleans /run/user

By default it doesn't (seem to), and we have no actual evidence that this is what's happening, so I'd prefer to say something less confident in the commit message, perhaps "systemd-tmpfiles might be configured to clean /run/user periodically, which could remove the session helper's p11-kit socket".

systemd-tmpfiles can be configured to periodically cleans /run/user,
which can remove the session helper's p11-kit socket. Once removed, all
subsequent Flatpak launches fail with "Can't find source path" until the
session helper restarts.

Take a shared flock on the .flatpak-helper directory for the lifetime
of the process. systemd-tmpfiles --clean skips directories that are
locked.

Helps: flatpak#6341
@swick
swick force-pushed the wip/tmpfile-cleanup-exclude branch from fb8bd49 to e0bde5c Compare August 6, 2026 22:25
@swick

swick commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

No matter if this is the root cause for everyone or no one there, this seems like the right thing to do anyway.

The commit is now just saying Helps: https://github.com/flatpak/flatpak/issues/6341 and systemd-tmpfiles can be configured to periodically clean....

@smcv

smcv commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

No matter if this is the root cause for everyone or no one there, this seems like the right thing to do anyway.

Yeah, agreed.

The commit is now just saying Helps: https://github.com/flatpak/flatpak/issues/6341 and systemd-tmpfiles can be configured to periodically clean....

Thanks, that seems completely appropriate.

@swick
swick added this pull request to the merge queue Aug 7, 2026
@swick
swick removed this pull request from the merge queue due to a manual request Aug 7, 2026
@swick
swick added this pull request to the merge queue Aug 7, 2026
Merged via the queue into flatpak:main with commit 0baf60c Aug 7, 2026
11 checks passed
@swick
swick deleted the wip/tmpfile-cleanup-exclude branch August 7, 2026 15:26
@smcv

smcv commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

As a note, this accidentally closed #6341 even though the Closes: had been removed from the commit message, because the PR description was still based on the old commit message. I reopened it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: bwrap: Can't find source path /run/user/1000/.flatpak-helper/pkcs11-flatpak-1644: No such file or directory

2 participants