Fd leak with explicit sync and kde plasma

[Cross posted from 497424 – fd leak with explicit sync (nvidia)]:

I also experience regular plasmashell crashes due to my notification-heavy workflow and leaking file descriptors.

Here’s a script that easily trigger this crash:

#!/bin/bash

NOTIFICATIONS=0
PREV_PID=""

if [[ "$__NV_DISABLE_EXPLICIT_SYNC" == "1" ]]; then
	echo "Explicit sync is disabled. Descriptors shouldn't leak."
else
	echo "Explicit sync is enabled. Descriptors should leak."
fi


while true; do
	PID=$(pidof plasmashell)

	# Check if PID has changed since the last execution. This is an indication that plasmashell has crashed.
	if [[ $PREV_PID != "" && "$PID" != "$PREV_PID" ]]; then
		echo "plasmashell crashed after $NOTIFICATIONS notifications"
		echo ""
		journalctl --no-pager --lines=100 | grep -C 10 "Too many open files"
		exit 1
	fi
	PREV_PID="$PID"

	if (( NOTIFICATIONS % 40 == 0 )); then
		echo ""
		echo "Notification    PID  Limit  Open descriptors  Until limit"
		echo "------------  -----  -----  ----------------  -----------"
	fi
	((NOTIFICATIONS++))

	kdialog --title "FD Leak" --passivepopup "Notification number $NOTIFICATIONS" 1 &

	# notify-send also leaks descriptors; either method will work.
	# notify-send "FD Leak" "Notification number $NOTIFICATIONS" --expire-time 1000

	# Get the descriptors and process's open files limit.
	FD_COUNT=$(ls -la /proc/$PID/fd 2>/dev/null | wc -l)
	LIMIT=$(cat /proc/$PID/limits | grep "Max open files" | awk '{print $4}')
	REMAINING=$(($LIMIT - $FD_COUNT))

	printf "%12d %6d %6d %17d %12d\n" $NOTIFICATIONS $PID $LIMIT $FD_COUNT $REMAINING

	# The notification rate isn't related to triggering a crash.
	sleep 0.25
done

This is a partial output from the script:

[12:43:20 user@fedroa-pc:[~]> ./leak.sh
Explicit sync is enabled. Descriptors should leak.

Notification    PID  Limit  Open descriptors  Until limit
------------  -----  -----  ----------------  -----------
           1   2563   1024               157          867
           2   2563   1024               157          867
[snip]
         218   2563   1024              1017            7
         219   2563   1024              1024            0
plasmashell crashed after 219 notifications

Mar 01 12:45:13 fedroa-pc plasmashell[2563]: qt.qpa.wayland: eglSwapBuffers failed with 0x3000, surface: 0x55db036bdf90
Mar 01 12:45:13 fedroa-pc plasmashell[2563]: qt.qpa.wayland: eglSwapBuffers failed with 0x3000, surface: 0x55db036bdf90
Mar 01 12:45:13 fedroa-pc plasmashell[2563]: qt.qpa.wayland: eglSwapBuffers failed with 0x3000, surface: 0x55db03438840
Mar 01 12:45:13 fedroa-pc plasmashell[2563]: qt.qpa.wayland: eglSwapBuffers failed with 0x3000, surface: 0x55db03438840
Mar 01 12:45:14 fedroa-pc plasmashell[2563]: error marshalling arguments for import_timeline: dup failed: Too many open files
Mar 01 12:45:14 fedroa-pc plasmashell[2563]: Error marshalling request: Too many open files
Mar 01 12:45:14 fedroa-pc plasmashell[2563]: qt.qpa.wayland: eglSwapBuffers failed with 0x3000, surface: 0x55db03f04800
Mar 01 12:45:14 fedroa-pc plasmashell[2563]: qt.qpa.wayland: eglSwapBuffers failed with 0x3000, surface: 0x55db03f04800
Mar 01 12:45:14 fedroa-pc plasmashell[2563]: The Wayland connection experienced a fatal error: Too many open files
Mar 01 12:45:14 fedroa-pc systemd[1983]: Starting grub-boot-success.service - Mark boot as successful...
Mar 01 12:45:14 fedroa-pc systemd[1983]: Finished grub-boot-success.service - Mark boot as successful.
Mar 01 12:45:14 fedroa-pc systemd[1983]: plasma-plasmashell.service: Main process exited, code=exited, status=255/EXCEPTION
Mar 01 12:45:14 fedroa-pc systemd[1983]: plasma-plasmashell.service: Failed with result 'exit-code'.
Mar 01 12:45:14 fedroa-pc systemd[1983]: plasma-plasmashell.service: Consumed 23.288s CPU time, 331.5M memory peak.

System info:

Operating System: Fedora Linux 41
KDE Plasma Version: 6.3.2
KDE Frameworks Version: 6.11.0
Qt Version: 6.8.2
Kernel Version: 6.13.5-200.fc41.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 16 × 11th Gen Intel® Core™ i7-11850H @ 2.50GHz
Memory: 62.6 GiB of RAM
Graphics Processor: NVIDIA RTX A3000 Laptop GPU/PCIe/SSE2
NVIDIA Driver Version: 570.124.04