Repository navigation
fix(rust): Do not drop messages in RunTaskInThreads under backpressure - #584
Merged
Merged
Conversation
RunTaskInThreads::poll kept forwarding completed tasks after the next step rejected a message, so a second rejection overwrote message_carried_over and silently dropped the earlier message. The same overwrite happened when retrying an existing carried-over message failed and the loop then forwarded another completed task. Stop forwarding completed tasks while a message is carried over. Later results stay in order in the handles queue until the carried-over message is accepted. Fixes #583 Co-Authored-By: Markus Unterwaditzer <markus@sentry.io>
untitaker
approved these changes
Oct 20, 2026
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.
Fixes #583.
RunTaskInThreads::pollcould silently drop messages when the next step applied backpressure. There were two ways this happened:poll(). The loop over finished handles kept going after aMessageRejected, so each rejection overwrotemessage_carried_over. This has been there since the strategy was first added (feat(rust-consumer): Add RunTaskInThreads strategy snuba#4537), and it's the case the Rust RunTaskInThreads loses pending messages when downstream applies backpressure #583 repro hits.if letbecame amatchin feat(rust): Strategy can return InvalidMessage error in poll, join, submit snuba#4929, so since then the loop runs anyway and can overwrite the pending message.The fix stops forwarding finished tasks while
message_carried_overis set. Later results stay in order in thehandlesqueue until the carried-over message is accepted, andsubmit()already applies backpressure upstream while a message is carried over.Tests
I added
test_backpressure_with_multiple_finished_tasks_does_not_drop_messages. It submits 3 messages, waits for all tasks to finish, polls 3 times while the next step rejects everything, then unblocks and joins. It asserts that[1, 2, 3]are delivered in order.To check that the test covers both paths, I ran it against three broken variants. Each one failed, delivering
[3]:breakafter an in-loop rejection)Checks run locally:
cargo fmt --check: passes.cargo test --lib -- --skip backends::kafka: 44 passed.cargo clippy --all-targets: same warnings asmain, nothing new.[1, 2].Not in scope
submit()checksself.handles.len() > self.concurrency, which lets one more task run than the configured concurrency allows. It predates both bugs. Changing it affects throughput, so I'd rather handle it separately.via markus.
--
View Junior Session [Sentry]