Skip to content

linux-v4l2: udev thread stops instead of spinning on a poll error (#1280) - #1310

Merged
zackees merged 2 commits into
masterfrom
fix/1280-v4l2-udev-poll-error
Oct 17, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/1280-v4l2-udev-poll-error

Conversation

@zackees

@zackees zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

Fixes #1280 (parent #1273).

Cause: udev_event_thread in plugins/linux-v4l2/v4l2-udev.c.h polled the udev netlink fd and the stop eventfd and continued whenever POLLIN was not set. A persistent POLLERR/POLLHUP/POLLNVAL makes poll() return immediately on every call, so the thread spun one core until shutdown.

Fix: the loop is factored into udev_monitor_loop(fd, stop_fd, stop, on_ready, ctx) (the thread passes the monitor fd, eventfd and a receive callback; normal path unchanged). If either fd reports POLLERR|POLLHUP|POLLNVAL, or poll() fails with errno != EINTR, it logs one LOG_WARNING (which fd, revents/errno) and returns; the thread cleans up its udev objects and exits. v4l2_unref_udev still signals and pthread_joins the finished thread. Hot-plug updates stop until restart.

Tests (Tier 2, new): test/cmocka/test_v4l2_udev_poll_error.c runs the real loop on pipes: monitor fd POLLHUP, monitor fd POLLNVAL, stop fd POLLHUP. Each must return within 50 ms in <= 2 iterations; the loop runs in a thread and is stopped via the stop event after the deadline, so a regression fails rather than hangs. No existing tests edited.

  • RED (de7883a): run.sh --repeat 1 --tests test_v4l2: test_v4l2_udev_poll_error Failed, all 3 cases at line 72 (loop never returned); other v4l2 tests passed.
  • GREEN: 8/8 test_v4l2* passed (udev_poll_error 0.03 s), including the repeat run.

Tiers 1/3/4: not applicable (C plugin bug fix, no Rust port involved).

Factors the udev thread's poll loop into udev_monitor_loop() with
injectable fds (behaviour unchanged) and adds test_v4l2_udev_poll_error,
which runs it on pipes reporting POLLHUP/POLLNVAL and expects it to stop.
#1280)

A persistent POLLERR/POLLHUP/POLLNVAL on the udev monitor fd or the stop
eventfd made poll() return at once forever while the loop continued: a
busy spin. Log once and leave the loop; a poll() failure other than EINTR
does the same. Shutdown still joins the (already finished) thread.
@zackees
zackees enabled auto-merge October 17, 2026 18:26
@zackees
zackees added this pull request to the merge queue Oct 17, 2026
Merged via the queue into master with commit 23d716f Oct 17, 2026
29 checks passed
@zackees
zackees deleted the fix/1280-v4l2-udev-poll-error branch October 26, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

linux-v4l2: udev monitor thread spins if poll keeps returning POLLERR/POLLHUP

1 participant