edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
Lane av1panichang: a worker panic ends the threaded decode with an error
Base: a62e7dc2 (main). Branch lane/av1panichang.
Goal
A panic on any worker of the threaded stream decode (decode_stream_with_threads
at threads > 1) must release every waiter and return an Err from the decode
call. It must never hang the process and never double-panic.
Waiters found
Every place a worker result is awaited in crates/ec-av1/src:
| Waiter | Where | Released by | Hang before this lane |
|---|---|---|---|
collect_one's rx.recv() |
stream/mod.rs |
one channel answer per dispatched job | yes: a job that unwound past its catch_unwind never sent, and the frame thread holds a Sender, so recv never disconnects |
SlotPromise::wait (condvar) |
stream/mod.rs |
fulfil / fail |
yes, once a fail panicked on a poisoned lock, the failure was never reached |
wavefront wave_barrier and dependent recon jobs |
decode/mod.rs |
active count and done[r] written by the worker |
yes: a panic in exec_op unwound out of wave_worker, so active and done[r] were never updated, and WaveGuard drop waited forever |
PipeSync::wait_for in pipe_run_lr |
decode/post_filter.rs |
note / close from pipe_run |
yes: a panic in pipe_run never closed lr_sync, and PipeGuard::finish waits on the batch that holds pipe_run_lr |
Batch::drop (pool join) |
par.rs |
the job wrapper's count decrement | a poisoned lock in the wrapper could skip the decrement; a re-raise during unwinding aborted the process |
Changes
crates/ec-av1/src/stream/mod.rsJobAnswer: a drop guard that owns a job's channel sender and its promises.sendanswers normally and fails the promises on an error reply.Dropanswers withError::corrupt("AV1 decode_stream: a worker thread panicked decoding a frame")and fails both promises if the job is still unanswered.- Frame jobs and show-existing jobs run their whole body inside an outer
catch_unwind, so no panic escapes into the pool'sBatch(which would re-raise it on the parsing thread at the end of the decode). SlotPromiselocks go through a poison-tolerantlock(), sofailandfulfilcannot panic after another panic.
crates/ec-av1/src/decode/mod.rswave_workerruns each recon job undercatch_unwind. A panicked job setsWaveQueue::failed, still updatesactiveanddone[r], and later jobs are drained without running, so the queue always empties.wave_checkreturnsErr("AV1 decode: a reconstruction worker thread panicked while decoding this tile")whenfailedis set. It is called at the end of each tile indecode/frame_tile.rsanddecode/key_tile.rs, afterflush_reconand before theWaveGuarddrops.
crates/ec-av1/src/decode/post_filter.rs:UnwindAbortguard inpipe_run. On unwind (std::thread::panicking()) it closes bothsyncandlr_syncwithabort. A normal return does not abort, so the restoration worker is not cut short.crates/ec-av1/src/par.rs:Batch's job wrapper andBatch::dropuse poison-tolerant locks, so the count always comes down and the wait always ends.Batch::dropre-raises a job panic only when the current thread is not already unwinding, which removes the double-panic abort.crates/ec-av1/src/fault.rs(new,#[doc(hidden)] pub mod faultinlib.rs): test-only fault injection.arm(site, nth)panics thenthtime a worker reaches a named site, once. Disarmed, a point is one relaxed atomic load. Sites:frame(inside a frame job's own catch),frame-after(past it, unwinding through the job),recon(a wavefront job),filter(a loop-filter band).crates/ec-av1/tests/worker_panic.rs(new):a_worker_panic_ends_the_decode_with_an_error_at_every_site: for each site, decodesfixtures/reelb_arf_witness.obuat 4 threads on a helper thread,recv_timeout60 s, and asserts anErrwhose text containspanicked.a_decode_after_a_worker_panic_still_works: an armed decode fails, then an unarmed decode at 4 threads succeeds and shows the same number of pictures as the 1-thread decode.
crates/ec-av1/src/stack_budget.rs:fault.rsadded to the by-value scan list.every_by_value_module_is_scannedrequires every modulelib.rsdeclares to be listed. The first full run failed on it, and the rerun is green.
Error text: the requested "worker panicked" wording is produced as a worker thread panicked ..., which keeps the panicked substring the test checks. The error kind is Error::corrupt in the existing ec_core helper style.
Verification
Run on host b with scripts/remote-run.sh av1panichang --host b, EC_MEMGUARD_MAX=6G.
cargo test --release -p ec-av1 --test worker_panic -- --test-threads=3: 2 passed, 0 failed (7.4 s). All four sites were reached: each armed decode returned anErr(expect_errwould fail on a site that was never hit).- Negative check: with the answer-on-unwind in
JobAnswer::dropdisabled, the same test fails withthe decode did not answer within 60s: it hung(theframe-aftersite). The change was reverted afterwards. The recon and filter sites were not re-checked against the pre-fix code. cargo test --release -p ec-av1 --no-fail-fast -- --test-threads=3(withEC_AV1_AOM_DIR=$HOME/.cache/aom-oracle, log at the lane scratchpad): every test binaryok.- lib: 816 passed, 0 failed, 49 ignored (3049 s).
aom_conformance: ok.fuzz_regressions: 5 passed.worker_panic: 2 passed.real_library: 1 ignored (personal media, needs--ignored).- Doc tests: 0 failed.
The first full run failed on
stack_budget::tests::every_by_value_module_is_scanned(the newfault.rs). The fix above was applied and the run restarted, so the numbers above are from the clean run.
cargo test --release -p ec-av1 --test aom_conformance -- --nocapturewithEC_AV1_AOM_DIR=$HOME/fixtures/av1-aom EC_REQUIRE_FIXTURES=1:aom vectors: 242/242 exact (611 shown frames), 0 refused by name, 0 known failing, 0 failed. The~/.cache/aom-oracledirectory on host b has no vectors, so the test skips there and that run is not the gate.cargo clippy -p ec-av1 --all-targets -- -D warnings: exit 0, 0 warnings.- Line counts: the largest file under
crates/ec-av1is 4848 lines (decode/rect.rs).decode/mod.rsandstream/mod.rsare under 5000 after the change.
Known limits
- A panic inside a loop-filter band (
par::Batchon the filter pool) is re-raised on the thread that waits for the batch. Inside a threaded stream decode that thread is a frame job, so it becomes anErr. A direct single-thread stream decode that uses the filter pool would still see the panic propagate to its caller. It does not hang. cargo fmt --checkis not clean on the crate at basea62e7dc2(many pre-existing diffs). The new and changed hunks were formatted by hand to rustfmt's output, andstream/mod.rswas clean at base and stays clean.- Fault injection is process-global, so the two tests in
worker_panic.rstake a mutex and run one at a time.