Repository navigation
Keep activity heartbeats in order when encoding is slow - #1977
Open
parbhatkapila4 wants to merge 3 commits into
Open
parbhatkapila4 wants to merge 3 commits into
parbhatkapila4 wants to merge 3 commits into
Conversation
Contributor
|
The issue seems valid, but the fix looks fairly overcomplicated. There's now three layers of queue draining, which shouldn't be necessary. Either simplify the solution, or create an issue instead. |
Author
|
Agreed, that was more than it needed. |
This branch has not been deployed
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.
Each
activity.heartbeat()call starts its own task to encode and record the details. When encoding actually awaits (a codec waiting on a remote KMS, or external storage), those tasks can finish out of order: a newer heartbeat gets recorded, then an older one lands after it. Core keeps the last recorded details, so a retried activity resumes from the older ones.The new test shows it on main: the activity heartbeats "first" then "second", the log shows ('second',) recorded before ('first',), and the retry gets "first".
The fix drops the queue. Only the newest heartbeat was ever sent, so the activity now keeps just that one, and each heartbeat task takes a per-activity lock before picking it up. Only one heartbeat encodes and records at a time, and a task that finds nothing left returns. asyncio.Lock wakes waiters in order, so the completion path awaiting
last_heartbeat_taskstill waits for every heartbeat ahead of it. Without the queue, heartbeat() can no longer raise QueueFull either.