fix: raise nofile soft limit to the hard limit at startup - #660
Open
V0UP3R wants to merge 1 commit into
Open
Conversation
cosmic-panel runs with the default soft limit for open file descriptors (1024 on Pop!_OS). On hybrid-GPU systems where the panel renders through the NVIDIA driver, the driver's Wayland explicit-sync path accumulates sync_file fds over time (NVIDIA/egl-wayland#196; observed at roughly one fd per swap, reaching several hundred within hours of normal use). When the process hits the 1024 fd ceiling every subsequent syscall that needs an fd fails with EMFILE: the Wayland connection can no longer be flushed ("Error trying to flush the wayland display: Too many open files"), all embedded applets get killed, and the panel exits. Repeated crashes drive cosmic-session's exponential restart backoff up, and rendering can also freeze without an exit, leaving the panel invisible until it is manually killed (pop-os#643). The leak itself is in the driver stack and cannot be fixed here, but the default ceiling makes the panel fall over within hours when it could run for weeks. cosmic-comp already raises its soft limit to the hard limit at startup for the same reason (src/utils/rlimit.rs); cosmic-panel is a sibling long-running compositing process under cosmic-session, but never gets that benefit since it is not a child of cosmic-comp. Raise the soft limit to the hard limit (1048576 by default) during startup, mirroring cosmic-comp. Applet processes spawned by the panel inherit the raised limit, which helps them as well since they render through the same driver stack (see cosmic-app-library#371). The panel does not exec arbitrary user commands, so the raised limit does not propagate outside COSMIC components. Testing: built and ran the patched panel on Pop!_OS 24.04 with an AMD iGPU + NVIDIA 580.173.02 hybrid setup; /proc/<pid>/limits shows the soft limit at 1048576 (previously 1024). The unpatched panel on this system leaks ~15-20 sync_file fds per minute of active use and crashes with EMFILE every few hours; with the raised limit the same leak rate takes weeks to reach the ceiling. Relates to pop-os#643. Assisted by an AI coding tool; I have reviewed and fully understand the change and am able to maintain it and respond to review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On hybrid-GPU systems where the panel renders through the NVIDIA driver,
cosmic-panelcrashes every few hours with EMFILE, or freezes invisible, because it exhausts the default soft limit of 1024 open file descriptors (#643).The journal signature at the moment of death is:
Root cause
The NVIDIA explicit-sync path leaks
sync_filefds inside the driver blob (NVIDIA/egl-wayland#196). On my system (AMD 680M iGPU + RTX 3050, driver 580.173.02) the panel accumulates 15-20anon_inode:sync_filefds per minute of active use;strace -kshows the leaked fds are created bydup3calls insidelibnvidia-eglcore.so.580.173.02and never closed. That leak is not fixable in cosmic-panel, but the default 1024 fd ceiling turns it into a crash within hours.cosmic-compalready raises its nofile soft limit to the hard limit at startup for exactly this class of problem (src/utils/rlimit.rs), but cosmic-panel is spawned by cosmic-session, not cosmic-comp, so it never gets that benefit and sits at the plain session default.Fix
Raise the soft limit to the hard limit (1048576 by default on Pop!_OS) during panel startup, mirroring cosmic-comp. This turns "crashes every few hours" into a ceiling that takes weeks of uptime to reach. Applet processes inherit the raised limit, which helps them too since they render through the same driver stack (cosmic-app-library#371 shows the same
sync_filepile-up). The panel does not exec arbitrary user commands, so the raised limit stays within COSMIC components.Testing
On the affected machine (Pop!_OS 24.04, COSMIC, AMD 680M + RTX 3050 hybrid, NVIDIA 580.173.02), A/B test with an artificially low soft limit to make the ceiling reachable quickly:
ulimit -Sn 300: dies in under 20 seconds withdup failed: Too many open files, exit code 1 — the exact production failure signature.ulimit -Sn 300: raises itself to 1048576 (verified via/proc/<pid>/limits), climbs past the 300 fd mark without any error, and runs until the test timeout ends it.cargo buildandcargo clippypass; the only warnings are pre-existing.Note: this is a mitigation for the driver-side leak, not a fix for it — the leak itself is tracked upstream at NVIDIA/egl-wayland#196.
Assisted by an AI coding tool; I have reviewed and fully understand the change and am able to maintain it and respond to review.