Add exception handling in task_worker_loop to prevent worker thread termination#7658
Add exception handling in task_worker_loop to prevent worker thread termination#7658
Conversation
Co-authored-by: eddyashton <6000239+eddyashton@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves the task system’s robustness by preventing exceptions thrown from BaseTask::do_task() from escaping the worker loop and terminating worker threads, and adds a regression test to ensure subsequent tasks still run after failures.
Changes:
- Add worker-level try/catch around
task->do_task()with logging forstd::exceptionand unknown exceptions. - Add a doctest verifying the worker continues processing after tasks throw.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/tasks/worker.h | Adds exception boundary + failure logging around task execution to keep worker threads alive. |
| src/tasks/test/basic_tasks.cpp | Adds a regression test covering continued execution after exceptions. |
|
@copilot apply changes based on the comments in this thread, and format all changes with |
…nization, format code Co-authored-by: eddyashton <6000239+eddyashton@users.noreply.github.com>
Applied all review feedback and formatted with clang-format (23843eb). All 13 tests pass with 265/265 assertions. |
| catch (const std::exception& e) | ||
| { | ||
| LOG_FAIL_FMT( | ||
| "{} task failed with exception: {}", task->get_name(), e.what()); |
There was a problem hiding this comment.
@eddyashton I think we need to at least trigger an orderly shutdown, or more likely abort in these situations, because we have a number of places in the code that throw an std::logic_error that is not particularly recoverable, and that may leave shared or thread local state that's fundamentally broken.
I think we should also try to print a stack trace here, at least when debug logging is enabled.
Task: Add try-catch block around do_task() in worker.h
<exception>include to worker.hOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.