Fixes #34573.
As mentioned in #34573 (comment), the ThreadPool PR (#33689) revealed an existing issue.
Before that PR, we were returning an incorrect error “Request rejected because http work queue depth exceeded” during shutdown for unhandled requests (we were not differentiating between “queue depth exceeded” and “server interrupted” errors). Now, with the ThreadPool inclusion, we return the proper error but we don’t handle it properly.
This PR improves exactly that. Handling the missing error and properly returning it to the user.
The race can be reproduced as follows:
- The server receives an http request.
- Processing of the request is delayed, and shutdown is triggered in the meantime.
- During shutdown, the libevent callback is unregistered and the threadpool interrupted.
- The delayed request (step 2) resumes and tries to submit a task to the now-interrupted server.
Reproduction test can be found #34577 (comment).
Also, to prevent this kind of issue from happening again, this PR changes task submission
to return the error as part of the function’s return value using util::Expected instead of
throwing the exception. Unlike exceptions, which require extra try-catch blocks and can be
ignored, returning Expected forces callers to explicitly handle failures, and attributes
like [[nodiscard]] allow us catch unhandled ones at compile time.