|
10 | 10 |
|
11 | 11 | import dev.restate.common.Slice; |
12 | 12 | import dev.restate.sdk.common.TerminalException; |
| 13 | +import dev.restate.sdk.core.statemachine.InvocationState; |
13 | 14 | import dev.restate.sdk.core.statemachine.StateMachine; |
14 | 15 | import dev.restate.sdk.endpoint.definition.HandlerDefinition; |
15 | 16 | import io.opentelemetry.context.Context; |
@@ -174,19 +175,19 @@ private CompletableFuture<Void> end( |
174 | 175 | HandlerContextInternal contextInternal, @Nullable Throwable exception) { |
175 | 176 | if (exception == null || ExceptionUtils.containsSuspendedException(exception)) { |
176 | 177 | contextInternal.close(); |
177 | | - } else { |
178 | | - LOG.warn("Error when processing the invocation", exception); |
| 178 | + } else if (contextInternal.getInvocationState() != InvocationState.CLOSED) { |
179 | 179 | if (ExceptionUtils.isTerminalException(exception)) { |
| 180 | + LOG.info("Invocation completed with terminal error", exception); |
180 | 181 | return contextInternal |
181 | 182 | .writeOutput((TerminalException) exception) |
182 | | - .thenAccept( |
183 | | - v -> { |
184 | | - LOG.trace("Closed correctly with non ok exception", exception); |
185 | | - contextInternal.close(); |
186 | | - }); |
| 183 | + .thenAccept(v -> contextInternal.close()); |
187 | 184 | } else { |
| 185 | + // No need to log here, fail inside will log |
188 | 186 | contextInternal.fail(exception); |
189 | 187 | } |
| 188 | + } else if (!"kotlinx.coroutines.JobCancellationException" |
| 189 | + .equals(exception.getClass().getCanonicalName())) { |
| 190 | + LOG.warn("Suppressed error after the invocation was closed:", exception); |
190 | 191 | } |
191 | 192 | return CompletableFuture.completedFuture(null); |
192 | 193 | } |
|
0 commit comments