|
13 | 13 | import graphql.kickstart.servlet.input.BatchInputPreProcessor;
|
14 | 14 | import java.io.IOException;
|
15 | 15 | import java.io.UncheckedIOException;
|
16 |
| -import java.util.Optional; |
17 | 16 | import java.util.concurrent.CancellationException;
|
18 | 17 | import java.util.concurrent.CompletableFuture;
|
19 | 18 | import java.util.concurrent.CompletionException;
|
@@ -58,14 +57,27 @@ private void invokeAndHandleAsync(
|
58 | 57 | asyncContext.setTimeout(configuration.getAsyncTimeout());
|
59 | 58 | AtomicReference<FutureExecutionResult> futureHolder = new AtomicReference<>();
|
60 | 59 | AsyncTimeoutListener timeoutListener =
|
61 |
| - event -> Optional.ofNullable(futureHolder.get()).ifPresent(FutureExecutionResult::cancel); |
| 60 | + event -> { |
| 61 | + log.warn( |
| 62 | + "GraphQL execution canceled because timeout of " |
| 63 | + + configuration.getAsyncTimeout() |
| 64 | + + " millis was reached. The following query was being executed when this happened:\n{}", |
| 65 | + String.join("\n", invocationInput.getQueries())); |
| 66 | + FutureExecutionResult futureResult = futureHolder.get(); |
| 67 | + if (futureResult != null) { |
| 68 | + futureResult.cancel(); |
| 69 | + } else { |
| 70 | + writeErrorResponse( |
| 71 | + invocationInput, request, response, listenerHandler, new CancellationException()); |
| 72 | + } |
| 73 | + }; |
62 | 74 | asyncContext.addListener(timeoutListener);
|
63 | 75 | asyncContext.start(
|
64 | 76 | () -> {
|
65 | 77 | FutureExecutionResult futureResult = invoke(invocationInput, request, response);
|
66 | 78 | futureHolder.set(futureResult);
|
67 | 79 | handle(futureResult, request, response, listenerHandler)
|
68 |
| - .thenAccept(it -> asyncContext.complete()); |
| 80 | + .thenAccept(it -> asyncContext.complete()); |
69 | 81 | });
|
70 | 82 | }
|
71 | 83 |
|
|
0 commit comments