diff --git a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/level/state/ExecutionLevelDispatchedState.kt b/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/level/state/ExecutionLevelDispatchedState.kt index db93a0b514..aa7b3ef807 100644 --- a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/level/state/ExecutionLevelDispatchedState.kt +++ b/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/level/state/ExecutionLevelDispatchedState.kt @@ -48,6 +48,7 @@ class ExecutionLevelDispatchedState( * for example: * parsing, validation, execution errors * persisted query errors + * an exception during execution was thrown */ private fun removeExecution(executionId: ExecutionId) { if (executions.containsKey(executionId)) { @@ -70,10 +71,8 @@ class ExecutionLevelDispatchedState( } return object : SimpleInstrumentationContext() { override fun onCompleted(result: ExecutionResult?, t: Throwable?) { - result?.let { - if (result.errors.size > 0) { - removeExecution(parameters.executionInput.executionId) - } + if ((result != null && result.errors.size > 0) || t != null) { + removeExecution(parameters.executionInput.executionId) } } } diff --git a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/syncexhaustion/state/SyncExecutionExhaustedState.kt b/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/syncexhaustion/state/SyncExecutionExhaustedState.kt index 14d1237585..c8cb8eb599 100644 --- a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/syncexhaustion/state/SyncExecutionExhaustedState.kt +++ b/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/syncexhaustion/state/SyncExecutionExhaustedState.kt @@ -51,6 +51,7 @@ class SyncExecutionExhaustedState( * for example: * - parsing, validation errors * - persisted query errors + * - an exception during execution was thrown */ private fun removeExecution(executionId: ExecutionId) { if (executions.containsKey(executionId)) { @@ -73,10 +74,8 @@ class SyncExecutionExhaustedState( } return object : SimpleInstrumentationContext() { override fun onCompleted(result: ExecutionResult?, t: Throwable?) { - result?.let { - if (result.errors.size > 0) { - removeExecution(parameters.executionInput.executionId) - } + if ((result != null && result.errors.size > 0) || t != null) { + removeExecution(parameters.executionInput.executionId) } } }