Skip to content

Commit

Permalink
Produce a 503 response when there no more worker threads to handle bl…
Browse files Browse the repository at this point in the history
…ocking requests

(cherry picked from commit dec72dc)
  • Loading branch information
cescoffier authored and aloubyansky committed Nov 7, 2023
1 parent 1a2264f commit 4bddbc5
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;

Expand Down Expand Up @@ -93,6 +94,12 @@ public void accept(Throwable throwable) {
event.response().end();
return;
}

if (event.failure() instanceof RejectedExecutionException) {
// No more worker threads - return a 503
event.response().setStatusCode(HttpResponseStatus.SERVICE_UNAVAILABLE.code()).end();
return;
}
} catch (IllegalStateException e) {
//ignore this if the response is already started
if (!event.response().ended()) {
Expand Down

0 comments on commit 4bddbc5

Please sign in to comment.