Skip to content

Commit

Permalink
[DRAFT 1751] Limit the time waiting for a handler to finish
Browse files Browse the repository at this point in the history
Bug: #1751
Signed-off-by: Pierre-Charles David <[email protected]>
  • Loading branch information
pcdavid committed Feb 22, 2023
1 parent 3312e9f commit cce90fc
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -214,9 +216,14 @@ public Mono<IPayload> handle(IInput input) {
Future<?> future = this.executorService.submit(() -> this.doHandle(payloadSink, input));
try {
// Block until the event has been processed
future.get();
future.get(5, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException exception) {
this.logger.warn(exception.getMessage(), exception);
} catch (TimeoutException e) {
// The handler did not finish, try to cancel it and return an error immeditaly instead of waiting (and
// blocking the current thread) indefinitely.
future.cancel(true);
return Mono.just((IPayload) new ErrorPayload(input.id(), this.messageService.timeout()));
}

// @formatter:off
Expand Down

0 comments on commit cce90fc

Please sign in to comment.