diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/submodel/InvokeOperationAsyncRequestHandler.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/submodel/InvokeOperationAsyncRequestHandler.java index 6a933b146..0540806e1 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/submodel/InvokeOperationAsyncRequestHandler.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/submodel/InvokeOperationAsyncRequestHandler.java @@ -166,6 +166,7 @@ protected InvokeOperationAsyncResponse executeOperation(Reference reference, Inv OperationHandle operationHandle = new OperationHandle(); handleOperationInvoke(reference, operationHandle, request); + AtomicBoolean operationFinished = new AtomicBoolean(false); AtomicBoolean timeoutOccured = new AtomicBoolean(false); ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); try { @@ -174,17 +175,27 @@ protected InvokeOperationAsyncResponse executeOperation(Reference reference, Inv request.getInoutputArguments().toArray(new OperationVariable[0]), (output, inoutput) -> { if (timeoutOccured.get()) { + LOGGER.debug("executeOperation: timeout already occurred - ignore success"); return; } + operationFinished.set(true); handleOperationSuccess(reference, operationHandle, inoutput, output); }, - error -> handleOperationFailure(reference, request.getInoutputArguments(), operationHandle, error)); + error -> { + operationFinished.set(true); + handleOperationFailure(reference, request.getInoutputArguments(), operationHandle, error); + }); executor.schedule(() -> { + if (operationFinished.get()) { + LOGGER.debug("executeOperation: operation already finished - ignore timeout"); + return; + } timeoutOccured.set(true); handleOperationTimeout(reference, request, operationHandle); }, request.getTimeout().getTimeInMillis(Calendar.getInstance()), TimeUnit.MILLISECONDS); } catch (Exception e) { + operationFinished.set(true); handleOperationFailure(reference, request.getInoutputArguments(), operationHandle, e); } finally { diff --git a/docs/source/other/release-notes.md b/docs/source/other/release-notes.md index 6725ef511..c04e22065 100644 --- a/docs/source/other/release-notes.md +++ b/docs/source/other/release-notes.md @@ -10,6 +10,7 @@ **Internal changes & bugfixes** - General - Model validation no longer throws an error if a model contains multiple instances of exactly the same Identifiable. This is not 100% correct behavior according to the specification as it validates the uniqueness criteria of their ID, however, it helps tremendously when working with existing SMTs as many of them are currently also not 100% standard-compliant and contain such duplicate elements. + - Fixed bug when executing an operation asynchronously. When the timeout has expired, the status of the operation was set to timeout, even if the operation already finished successfully. This does no longer happen - the timeout no longer overwrites the result of the operation. - Endpoint - HTTP - Fixed query modifier `extent` which has not been working as intended