Skip to content

test: Fix the force_camera race in test_v4l2_busy_signal's fake libv4l2 - #997

Merged
zackees merged 2 commits into
masterfrom
fix/953-v4l2-busy-signal-race
Oct 16, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/953-v4l2-busy-signal-race

Conversation

@zackees

@zackees zackees commented Oct 16, 2026

Copy link
Copy Markdown
Member

Fixes #953.

Cause (test fixture, not the plugin): the fake libv4l2 in test_v4l2_busy_signal.c answered EBUSY while waitpid(holder, WNOHANG) == 0. After Force Camera's SIGTERM, the holder closes its fds before it becomes a reapable zombie. The plugin's /proc scan sees the device free in that window (released is true), but the reopen's waitpid(WNOHANG) can still return 0, so the fake said busy, fake.holder kept the pid, and force_camera_closes_the_holder_and_opens_the_camera failed with <pid> != 0. Machine load (Tier 2 -j4) widens the window.

RED (test: Force Camera must reopen while the holder is still exiting): a holder variant that, on SIGTERM, closes the device and then takes 300 ms to exit, holding that window open every time. New case force_camera_opens_while_the_holder_is_still_exiting. Locally it failed with 10148 != 0 at test_v4l2_busy_signal.c:344 (the fake.holder == 0 check): the flake's signature, made deterministic. The existing cases still pass.

GREEN (test: The fake libv4l2 frees the camera when its holder lets go): the fake treats the device as busy only while /proc/<pid>/fd still has the camera open (the plugin's own view). Otherwise it waits for the exiting holder, so its SIGTERM status is recorded deterministically. The ignore_term holder keeps its fd and stays busy.

Local: ./lint ok; Tier 2 OFF: test_v4l2_busy_signal passes, new case included. That run (machine heavily loaded) also hit test_async_delay_audio, test_deinterlace_2x_field_order and test_media_restart_stale_frame, the real-time media flakes of #838. The harness stops there, so the v4l2 repeats and the ON build were not run locally; PR CI runs both.

A new holder variant closes the device on SIGTERM and then takes 300 ms
to exit, holding open the window machine load opens in the plain holder:
fds closed, not yet a reapable zombie. The plugin sees the device free,
but the fake libv4l2 still calls the holder alive (waitpid WNOHANG
returns 0) and answers EBUSY, so the reopen fails. This is the
intermittent force_camera_closes_the_holder_and_opens_the_camera
failure, made deterministic.

Refs #953
holder_alive() called the holder alive whenever waitpid(WNOHANG)
returned 0, including the window after SIGTERM where the holder has
closed its fds but is not yet a reapable zombie. The plugin's /proc
scan already sees the device free there, so the reopen got EBUSY and
force_camera_closes_the_holder_and_opens_the_camera failed under load.
The fake now treats the device as busy only while /proc/<pid>/fd still
has the camera open (the plugin's own view), and otherwise waits for
the exiting holder, so its SIGTERM status is recorded deterministically.

Fixes #953
@zackees
zackees added this pull request to the merge queue Oct 16, 2026
@zackees
zackees removed this pull request from the merge queue due to a manual request Oct 16, 2026
@zackees
zackees merged commit e3901ad into master Oct 16, 2026
23 checks passed
@zackees
zackees deleted the fix/953-v4l2-busy-signal-race branch October 26, 2026 15:44
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.

Flaky: test_v4l2_busy_signal force_camera_closes_the_holder_and_opens_the_camera fails under Tier 2 -j4

1 participant