aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.2k stars 853 forks source link

Fix issue where the Scheduled Timeout was incorrectly completing the futures with empty messages #5571

Closed joviegas closed 2 months ago

joviegas commented 2 months ago

Motivation and Context

The key modification was ensuring that the same future passed to receiveQueueBuffer.receiveMessage is the one that gets completed, regardless of whether a timeout occurs.

Previously, a new future (timeoutFuture) was scheduled to complete after the timeout period, but this future was independent of the one added to the futures queue. Now, instead of creating a new timeout future, we directly complete the original future (receiveMessageFuture) if it hasn't already been completed before the timeout occurs.

Root Cause

The issue occurred because a new CompletableFuture (timeout future) was being created and completed during timeouts, rather than completing the original future added to the ReceiveBuffer. This left the original future uncompleted, causing the buffer to return empty responses.

Fix

The fix ensures that the same receiveMessageFuturepassed to the buffer is completed, even when a timeout occurs. The timeout logic now checks if the original future is complete and directly completes it, avoiding the creation of a separate timeout future. This ensures that the buffer behaves correctly and returns the expected messages.

Modifications

The key modification was ensuring that the same future passed to receiveQueueBuffer.receiveMessage is the one that gets completed, regardless of whether a timeout occurs.

Previously, a new future (timeoutFuture) was scheduled to complete after the timeout period, but this future was independent of the one added to the futures queue. Now, instead of creating a new timeout future, we directly complete the original future (receiveMessageFuture) if it hasn't already been completed before the timeout occurs.

Testing

License

sonarcloud[bot] commented 2 months ago

Quality Gate Failed Quality Gate failed

Failed conditions
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint