Skip to content

Allow async timeout to be configured #184 #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public String executeQuery(String query) {
private void doRequestAsync(HttpServletRequest request, HttpServletResponse response, HttpRequestHandler handler) {
if (configuration.isAsyncServletModeEnabled()) {
AsyncContext asyncContext = request.startAsync(request, response);
asyncContext.setTimeout(configuration.getAsyncTimeout());
HttpServletRequest asyncRequest = (HttpServletRequest) asyncContext.getRequest();
HttpServletResponse asyncResponse = (HttpServletResponse) asyncContext.getResponse();
configuration.getAsyncExecutor().execute(() -> doRequest(asyncRequest, asyncResponse, handler, asyncContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.function.Supplier;
import lombok.Getter;

public class GraphQLConfiguration {

Expand All @@ -32,12 +33,14 @@ public class GraphQLConfiguration {
private final boolean asyncServletModeEnabled;
private final Executor asyncExecutor;
private final long subscriptionTimeout;
@Getter
private final long asyncTimeout;
private final ContextSetting contextSetting;

private GraphQLConfiguration(GraphQLInvocationInputFactory invocationInputFactory,
GraphQLQueryInvoker queryInvoker,
GraphQLObjectMapper objectMapper, List<GraphQLServletListener> listeners, boolean asyncServletModeEnabled,
Executor asyncExecutor, long subscriptionTimeout, ContextSetting contextSetting,
Executor asyncExecutor, long subscriptionTimeout, long asyncTimeout, ContextSetting contextSetting,
Supplier<BatchInputPreProcessor> batchInputPreProcessor) {
this.invocationInputFactory = invocationInputFactory;
this.queryInvoker = queryInvoker;
Expand All @@ -47,6 +50,7 @@ private GraphQLConfiguration(GraphQLInvocationInputFactory invocationInputFactor
this.asyncServletModeEnabled = asyncServletModeEnabled;
this.asyncExecutor = asyncExecutor;
this.subscriptionTimeout = subscriptionTimeout;
this.asyncTimeout = asyncTimeout;
this.contextSetting = contextSetting;
this.batchInputPreProcessor = batchInputPreProcessor;
}
Expand Down Expand Up @@ -119,8 +123,9 @@ public static class Builder {
private boolean asyncServletModeEnabled = false;
private Executor asyncExecutor = Executors.newCachedThreadPool(new GraphQLThreadFactory());
private long subscriptionTimeout = 0;
private long asyncTimeout = 30;
private ContextSetting contextSetting = ContextSetting.PER_QUERY_WITH_INSTRUMENTATION;
private Supplier<BatchInputPreProcessor> batchInputPreProcessorSupplier = () -> new NoOpBatchInputPreProcessor();
private Supplier<BatchInputPreProcessor> batchInputPreProcessorSupplier = NoOpBatchInputPreProcessor::new;

private Builder(GraphQLInvocationInputFactory.Builder invocationInputFactoryBuilder) {
this.invocationInputFactoryBuilder = invocationInputFactoryBuilder;
Expand Down Expand Up @@ -178,6 +183,11 @@ public Builder with(long subscriptionTimeout) {
return this;
}

public Builder asyncTimeout(long asyncTimeout) {
this.asyncTimeout = asyncTimeout;
return this;
}

public Builder with(ContextSetting contextSetting) {
if (contextSetting != null) {
this.contextSetting = contextSetting;
Expand Down Expand Up @@ -208,6 +218,7 @@ public GraphQLConfiguration build() {
asyncServletModeEnabled,
asyncExecutor,
subscriptionTimeout,
asyncTimeout,
contextSetting,
batchInputPreProcessorSupplier
);
Expand Down