Skip to content

threadpool: fix a race condition in error handling#4116

Merged
kleisauke merged 2 commits into
libvips:8.15from
kleisauke:8.15-fix-threadpool-error
Aug 25, 2024
Merged

threadpool: fix a race condition in error handling#4116
kleisauke merged 2 commits into
libvips:8.15from
kleisauke:8.15-fix-threadpool-error

Conversation

@kleisauke

Copy link
Copy Markdown
Member

Fixes a regression introduced in commit 9248ab7 (PR #3105).

Targets the 8.15 branch.

Context: #4107 (comment).

@jcupitt

jcupitt commented Aug 25, 2024

Copy link
Copy Markdown
Member

Ahhhh! Great spot, yes this was a dumb race condition.

Returning the error from vips_threadpool_free() feels like two ideas are being conflated. How about adding vips_threadpool_wait() to wait for all threads to finish, and calling that from vips_threadpool_free()? Then the end of vips_threadpool_run() can wait for all threads to finish, get any error, and free the threadpool. You wouldn't need to handle errors in the free function.

@kleisauke kleisauke force-pushed the 8.15-fix-threadpool-error branch from 19a3436 to 60bf929 Compare August 25, 2024 10:54
@kleisauke kleisauke changed the title threadpool: fetch pool->error until all workers have completed threadpool: fix a race condition in error handling Aug 25, 2024
@kleisauke kleisauke force-pushed the 8.15-fix-threadpool-error branch from 60bf929 to 0e7811f Compare August 25, 2024 10:58
@kleisauke

Copy link
Copy Markdown
Member Author

Good idea. Addressed in the latest revision.

@jcupitt

jcupitt commented Aug 25, 2024

Copy link
Copy Markdown
Member

Do you need the wait param? It's fine to call vips_threadpool_free() many times, I think.

@kleisauke

Copy link
Copy Markdown
Member Author

I wasn't sure about that one, let me try to remove it. It was inspired by g_thread_pool_free().

Fixes a regression introduced in commit 9248ab7 (PR libvips#3105).
@kleisauke kleisauke force-pushed the 8.15-fix-threadpool-error branch from 0e7811f to c8ee345 Compare August 25, 2024 11:41
@kleisauke

Copy link
Copy Markdown
Member Author

... you're right, it doesn't matter that vips_threadpool_wait() is now called twice. It makes the diff also easier to read now. :)

@jcupitt

jcupitt commented Aug 25, 2024

Copy link
Copy Markdown
Member

Looks great!

@kleisauke kleisauke merged commit b3ce0a9 into libvips:8.15 Aug 25, 2024
@kleisauke kleisauke deleted the 8.15-fix-threadpool-error branch August 25, 2024 12:05
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.

2 participants