Skip to content

fix(thread): clean up when a worker cannot be created - #1591

Open
lusoris wants to merge 1 commit into
Netflix:masterfrom
VMAFx:fix/thread-pool-create-errors
Open

lusoris wants to merge 1 commit into
Netflix:masterfrom
VMAFx:fix/thread-pool-create-errors

Conversation

@lusoris

@lusoris lusoris commented Sep 8, 2026

Copy link
Copy Markdown

vmaf_thread_pool_create() ignores pthread_create() errors, detaches an uninitialized thread handle after a failure, and still reports success with the requested worker count. Destruction can then wait forever for workers that were never started.

Check the creation result, set the worker count under the queue lock to the number actually started, stop and release those workers, clear the output pointer, and return the negative pthread error. Also clear the output pointer after the worker-array allocation fails, since that path has already freed the pool. Successful creation is unchanged; this does not introduce a partially sized successful pool.

The regression injects EAGAIN at the first and second pthread_create() calls and ENOMEM at the worker-array allocation. It checks the error, null output, no detach of an uncreated worker, and a successful retry with a real queued job. Each case fails independently against the original implementation. The new test has a ten-second timeout so a teardown regression is bounded.

Validation against upstream f85a853692a8c730d0270cd733c8bb30b5b93b7c, x86-64 Linux, GCC 15.2.0, Meson 1.10.1:

meson setup build-release libvmaf --buildtype=release -Denable_cuda=false -Denable_float=true -Denable_docs=false
ninja -C build-release
meson test -C build-release --print-errorlogs
# 24/24 passed

meson setup build-sanitize libvmaf --buildtype=debug -Db_sanitize=address,undefined -Denable_cuda=false -Denable_float=true -Denable_docs=false
ninja -C build-sanitize
ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=halt_on_error=1 meson test -C build-sanitize test_thread_pool test_thread_pool_create_errors --print-errorlogs
# both passed; all three original-source negative controls failed as expected

No scoring code or golden-data assertions changed. Sanitizer acceptance here is for the two thread-pool targets; separate baseline leaks in upstream test_predict and test_pic_preallocation remain outside this patch. This fixes construction failure cleanup; callers must still coordinate ordinary pool lifetime with their producers.

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