fix(aws_s3 source): complete in-flight SQS message processing before shutdown#24670
Open
sanjams2 wants to merge 6 commits intovectordotdev:masterfrom
Open
fix(aws_s3 source): complete in-flight SQS message processing before shutdown#24670sanjams2 wants to merge 6 commits intovectordotdev:masterfrom
sanjams2 wants to merge 6 commits intovectordotdev:masterfrom
Conversation
…shutdown Refactor IngestorProcess::run() to use a two-phase approach that prevents the shutdown race condition where tokio::select! could cancel run_once() mid-flight, leaving SQS messages undeleted and causing duplicate delivery after visibility_timeout. Phase 1 (cancellable): receive_with_backoff() polls SQS for messages, handling errors with exponential backoff. This phase is safe to cancel via select! because no messages have been received yet. Phase 2 (non-cancellable): process_messages() handles each message, forwards deferred entries, and batch-deletes successfully processed messages. This phase runs to completion without being raced against shutdown, ensuring SQS deletes are never skipped. The old run_once() method is replaced by receive_with_backoff() and process_messages(), with all existing behavior preserved: error metrics, deferred queue forwarding, batch delete handling, and backoff logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
During shutdown,
tokio::select!inIngestorProcess::run()cancelsrun_once()mid-flight, which can leave SQS messages undeleted after events have already been sent to sinks, causing duplicate delivery aftervisibility_timeoutexpires.Fix
Split
run_once()into two distinct phases:Cancellable
receive_with_backoff()— polls SQS for messages with exponential backoff on errors. This is raced against shutdown inselect!and is safe to cancel because no messages have been processed yet.Non-cancellable
process_messages()— handles each received message, forwards deferred entries, and batch-deletes successfully processed messages from SQS. This runs to completion without being raced against shutdown, ensuring SQS deletes are never skipped.This preserves all existing behavior (error metrics, deferred queue forwarding, batch delete handling, backoff logic) while eliminating the race condition.
Tests
Added 3 new unit tests:
shutdown_interrupts_long_poll— verifies that shutdown interrupts the SQS receive phase cleanlyshutdown_interrupts_backoff_sleep— verifies that shutdown interrupts the backoff sleep between retriesinflight_processing_completes_despite_shutdown— verifies that in-flight message processing (including SQS delete) runs to completion even when shutdown fires mid-processingCloses #24010