-
Notifications
You must be signed in to change notification settings - Fork 28
Fix orphaned FUSE daemon process after AppImage exit #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: probonopd <2480569+probonopd@users.noreply.github.com>
Co-authored-by: probonopd <2480569+probonopd@users.noreply.github.com>
Co-authored-by: probonopd <2480569+probonopd@users.noreply.github.com>
Co-authored-by: probonopd <2480569+probonopd@users.noreply.github.com>
You're absolutely right. The previous approach would have caused the FUSE daemon to terminate before AppRun started, which is the same issue as #119. I've changed the implementation to fork before exec (commit 2442c30). Now:
This keeps the FUSE mount alive during AppRun's execution while ensuring proper cleanup afterward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the AppImage runtime to properly manage the lifecycle of the FUSE daemon by forking before executing AppRun. The change ensures that the keepalive pipe can be closed after AppRun exits, which signals the FUSE daemon to terminate.
Key changes:
- Implements fork/exec pattern to launch AppRun in a child process while parent waits
- Captures and propagates AppRun's exit status correctly (normal exit, signal termination)
- Closes the keepalive pipe after AppRun exits to trigger FUSE daemon cleanup
Reviewed Changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/runtime/runtime.c | Implements fork/exec pattern for AppRun execution with proper exit status handling and keepalive pipe management |
| .gitignore | Adds CodeQL detected source root to ignored files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| exit(EXIT_EXECERROR); | ||
| } | ||
|
|
||
| if (apprun_pid == 0) { |
Copilot
AI
Nov 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The child process inherits both ends of the keepalive pipe but doesn't use them. Both pipe ends should be closed before execv() to prevent the child from holding unnecessary file descriptors. Add close(keepalive_pipe[0]); and close(keepalive_pipe[1]); before the execv call on line 1858.
| if (apprun_pid == 0) { | |
| if (apprun_pid == 0) { | |
| /* Child process - close keepalive pipe before exec */ | |
| close(keepalive_pipe[0]); | |
| close(keepalive_pipe[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an obvious oversight that was there before. I am just a little concerned that the pipe loses its usefulness when it is closed here already. (Yes, technically the parent process would keep its side open anyway).
This needs to be tested thoroughly. The nature of the bug requires a quite sophisticated setup, though, which is time consuming.
src/runtime/runtime.c
Outdated
| } else { | ||
| /* Parent process - wait for AppRun to finish, then close pipe */ | ||
| int status; | ||
| waitpid(apprun_pid, &status, 0); |
Copilot
AI
Nov 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value of waitpid() is not checked. If waitpid() fails (returns -1), the status variable will be uninitialized, leading to undefined behavior in the subsequent WIFEXITED/WIFSIGNALED checks. Check the return value and handle errors appropriately.
| waitpid(apprun_pid, &status, 0); | |
| pid_t waited_pid = waitpid(apprun_pid, &status, 0); | |
| if (waited_pid == -1) { | |
| perror("waitpid error"); | |
| close(keepalive_pipe[0]); | |
| exit(EXIT_EXECERROR); | |
| } |
| if (WIFEXITED(status)) { | ||
| exit(WEXITSTATUS(status)); | ||
| } else if (WIFSIGNALED(status)) { | ||
| /* Child was killed by a signal, exit with 128 + signal number */ | ||
| exit(128 + WTERMSIG(status)); | ||
| } else { | ||
| exit(EXIT_EXECERROR); |
Copilot
AI
Nov 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memory allocated for real_argv on line 1807 is never freed before these exit calls, causing a memory leak. While the process is exiting anyway, it's better practice to free(real_argv) before the exit calls or restructure to ensure cleanup happens.
|
@copilot address all points raised in the review above |
…leak Co-authored-by: probonopd <2480569+probonopd@users.noreply.github.com>
All review points addressed in commit 876881d:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Build for testing: |
Fix for AppImage orphan process surviving main process exit
Problem:
An orphaned FUSE daemon process survives after the main AppImage process exits, particularly in non-interactive environments like systemd services. The daemon stays alive indefinitely in sleep state, reading from /dev/fuse.
Root Cause:
The keepalive pipe read end (keepalive_pipe[0]) was not being closed at the right time. If closed before exec, the FUSE daemon would terminate before AppRun starts (issue #119). If inherited by AppRun without proper cleanup, the pipe might not break when AppRun exits.
Solution:
Fork before executing AppRun:
Benefits:
Plan:
Changes Made:
Security Summary:
All review feedback addressed:
Original prompt
This section details on the original issue you should resolve
<issue_title>AppImage orphan survives main process exit</issue_title>
<issue_description>I am seeing an orphaned process get left behind under some conditions after main process exits. This orphaned process seems to stay around forever in sleep state until reboot. I originally noticed this when appimage was run by a process running as a systemd service similar to #99 so I have put together the following example without systemd.
Running as root to demonstrate that it should not be a permissions issue.
Using following as entrypoint from appimage wrapper:
Running with strace to trace processes. We can see that main process forks pid 30812 (which I believe is this fork call) which then forks again with pid 30813. Main process then eventually execs our "Hello world!" script which exits properly. However we can see that a detached process is left behind which is pid 30813.
30813 appears to be in s...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.