-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added ExecutionInput cancellation #3880
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
Conversation
Test Results 313 files ±0 313 suites ±0 48s ⏱️ -1s Results for commit bd4a098. ± Comparison against base commit 5a03541. This pull request removes 150 and adds 130 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
This should be combined with #3876 |
…ncellation-of-request # Conflicts: # src/main/java/graphql/execution/AsyncExecutionStrategy.java # src/main/java/graphql/execution/AsyncSerialExecutionStrategy.java # src/main/java/graphql/execution/ExecutionStrategy.java # src/main/java/graphql/execution/SubscriptionExecutionStrategy.java
…uest # Conflicts: # src/main/java/graphql/execution/ExecutionContext.java # src/main/java/graphql/execution/ExecutionStrategy.java
@@ -306,11 +332,18 @@ public Builder graphQLContext(Map<?, Object> mapOfContext) { | |||
} | |||
|
|||
// hidden on purpose | |||
private Builder transfer(GraphQLContext graphQLContext) { | |||
private Builder internalTransferContext(GraphQLContext graphQLContext) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can rename because its private method. This is a transferring of the context to a new instance
@@ -483,7 +483,6 @@ private CompletableFuture<ExecutionResult> parseValidateAndExecute(ExecutionInpu | |||
private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput> executionInputRef, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) { | |||
|
|||
ExecutionInput executionInput = executionInputRef.get(); | |||
String query = executionInput.getQuery(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never used. Grey code. took the opportunity to remove it
@@ -22,11 +22,12 @@ public AbstractAsyncExecutionStrategy(DataFetcherExceptionHandler dataFetcherExc | |||
} | |||
|
|||
protected BiConsumer<List<Object>, Throwable> handleResults(ExecutionContext executionContext, List<String> fieldNames, CompletableFuture<ExecutionResult> overallResult) { | |||
return (List<Object> results, Throwable exception) -> executionContext.run(() -> { | |||
return (List<Object> results, Throwable exception) -> executionContext.run(exception, () -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whenever we call run
here we need to respect if an exception was thrown on the inside when we check if we are cancelled.
There is not point throwing a "cancelled" exception if we are already in exception
* @param executionId the id of the current execution | ||
* @param graphQLContext the graphql context | ||
*/ | ||
void runningStateChanged(ExecutionId executionId, GraphQLContext graphQLContext, RunningState runningState); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made i an enum versus a boolean
@@ -371,48 +376,89 @@ public boolean isRunning() { | |||
return isRunning.get() > 0; | |||
} | |||
|
|||
public void incrementRunning() { | |||
if (isRunning.incrementAndGet() == 1 && engineRunningObserver != null) { | |||
engineRunningObserver.runningStateChanged(executionId, graphQLContext, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never needed to be public. Never used publically
checkIsCancelled(throwable); | ||
|
||
if (isRunning.incrementAndGet() == 1) { | ||
changeOfState(RUNNING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changeOfState encapsulates the null check
if (isRunning.incrementAndGet() == 1 && engineRunningObserver != null) { | ||
engineRunningObserver.runningStateChanged(executionId, graphQLContext, true); | ||
private void incrementRunning(Throwable throwable) { | ||
checkIsCancelled(throwable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we now check if we are cancelled in a common place
return executionResult; | ||
}); | ||
}); | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like formatting
@ExperimentalApi | ||
@NullMarked | ||
public interface EngineRunningObserver { | ||
|
||
enum RunningState { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add started and finished here to make it complete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not .., we have ways to detect that
… asked for
Addressing #3879
This allows the graphql operation to be co-operatively cancelled. It use the "engine run state" tracking to know when its a good time to cancel and abort