Skip to content

udev-monitor: make the monitor fd non-blocking#19

Open
lwhsu wants to merge 1 commit into
wulf7:masterfrom
lwhsu:udev-monitor-non-blocking
Open

udev-monitor: make the monitor fd non-blocking#19
lwhsu wants to merge 1 commit into
wulf7:masterfrom
lwhsu:udev-monitor-non-blocking

Conversation

@lwhsu

@lwhsu lwhsu commented Jul 10, 2026

Copy link
Copy Markdown

systemd's libudev documents that the monitor socket is non-blocking by default:

https://github.com/systemd/systemd/blob/v261/src/libudev/libudev-monitor.c#L228-L231

It also creates the monitor socket with SOCK_NONBLOCK:

https://github.com/systemd/systemd/blob/v261/src/libsystemd/sd-device/device-monitor.c#L179-L183

libudev-devd currently uses a blocking pipe. Once all pending events have been consumed, another call to udev_monitor_receive_device() blocks instead of returning NULL with EAGAIN.

This was observed in KWin, where display hotplug handling stalled after disconnecting and reconnecting an external display in a KDE/Wayland session.

Set O_NONBLOCK on the read end returned by udev_monitor_get_fd(). Keep the internal write end blocking to preserve the current producer and backpressure behavior.

Sponsored by: The FreeBSD Foundation

systemd's libudev documents that the monitor socket is non-blocking by
default:

https://github.com/systemd/systemd/blob/v261/src/libudev/libudev-monitor.c#L228-L231

It also creates the monitor socket with SOCK_NONBLOCK:

https://github.com/systemd/systemd/blob/v261/src/libsystemd/sd-device/device-monitor.c#L179-L183

libudev-devd currently uses a blocking pipe. Once all pending events
have been consumed, another call to udev_monitor_receive_device()
blocks instead of returning NULL with EAGAIN.

This was observed in KWin, where display hotplug handling stalled after
disconnecting and reconnecting an external display in a KDE/Wayland
session.

Set O_NONBLOCK on the read end returned by udev_monitor_get_fd(). Keep
the internal write end blocking to preserve the current producer and
backpressure behavior.

Sponsored by:	The FreeBSD Foundation
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