Skip to content

fix: raise nofile soft limit to the hard limit at startup - #660

Open
V0UP3R wants to merge 1 commit into
pop-os:masterfrom
V0UP3R:fix/raise-nofile-limit
Open

fix: raise nofile soft limit to the hard limit at startup#660
V0UP3R wants to merge 1 commit into
pop-os:masterfrom
V0UP3R:fix/raise-nofile-limit

Conversation

@V0UP3R

@V0UP3R V0UP3R commented Jul 30, 2026

Copy link
Copy Markdown

Problem

On hybrid-GPU systems where the panel renders through the NVIDIA driver, cosmic-panel crashes 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:

cosmic-session[3332]: error marshalling arguments for import_timeline: dup failed: Too many open files
cosmic-session[3332]: Error trying to flush the wayland display: Too many open files (os error 24)
cosmic-panel[987403]: com.system76.CosmicAppletAudio: exited with code 137
[... every embedded applet killed, panel exits with code 1, restart counter grows]

Root cause

The NVIDIA explicit-sync path leaks sync_file fds inside the driver blob (NVIDIA/egl-wayland#196). On my system (AMD 680M iGPU + RTX 3050, driver 580.173.02) the panel accumulates 15-20 anon_inode:sync_file fds per minute of active use; strace -k shows the leaked fds are created by dup3 calls inside libnvidia-eglcore.so.580.173.02 and never closed. That leak is not fixable in cosmic-panel, but the default 1024 fd ceiling turns it into a crash within hours.

cosmic-comp already 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_file pile-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:

  • Unpatched panel started with ulimit -Sn 300: dies in under 20 seconds with dup failed: Too many open files, exit code 1 — the exact production failure signature.
  • Patched panel started with the same 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 build and cargo clippy pass; 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.

  • I have disclosed use of any AI generated code in my commit messages.
  • I understand these changes in full and will be able to respond to review comments.
  • My change is accurately described in the commit message.
  • My contribution is tested and working as described.
  • I have read the Developer Certificate of Origin and certify my contribution under its conditions.

Assisted by an AI coding tool; I have reviewed and fully understand the change and am able to maintain it and respond to review.

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.
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.

1 participant