Skip to content

Commit

Permalink
Fix #1803: Ensure the getOperation doesn't change operation status
Browse files Browse the repository at this point in the history
  • Loading branch information
zcgandcomp committed Dec 13, 2024
1 parent 6084bca commit b3173f5
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,10 @@ public OperationDetailResponse operationDetail(OperationDetailRequest request) t
});

final String userId = request.getUserId();
final OperationEntity operationEntity = expireOperation(
claimOperation(operation, userId, currentTimestamp),
currentTimestamp
);
final OperationEntity operationEntity =
claimOperation(operation, userId, currentTimestamp);
final OperationDetailResponse operationDetailResponse = convertFromEntityAndFillOtp(operationEntity);
expireOperation(operationDetailResponse,currentTimestamp);
extendAndSetOperationDetailData(operationDetailResponse);
return operationDetailResponse;
} catch (GenericServiceException ex) {
Expand Down Expand Up @@ -1013,6 +1012,17 @@ private OperationEntity expireOperation(OperationEntity operationEntity, Date cu
return operationEntity;
}

private void expireOperation(OperationDetailResponse operation, Date currentTimestamp) throws GenericServiceException {
// Operation is still pending and timestamp is after the expiration.
if (OperationStatus.PENDING.equals(operation.getStatus())
&& operation.getTimestampExpires().before(currentTimestamp)) {
// Operation status is persisted only using background service to avoid database deadlocks,
// because two concurrent UPDATE queries can be executed at the same time.
// The status in the database may be updated few seconds later for this reason.
operation.setStatus(OperationStatus.EXPIRED);
}
}

private boolean factorsAcceptable(@NotNull OperationEntity operation, PowerAuthSignatureTypes usedFactor) {
final String operationId = operation.getId();
final PowerAuthSignatureTypes[] allowedFactors = operation.getSignatureType();
Expand Down

0 comments on commit b3173f5

Please sign in to comment.