Addresses two race conditions in background task runs #14115
Merged
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.
During reliability testing of background tasks, I kept experiencing hangs that
couldn't be explained by task deadlocking due to the
limit
on the worker (see#14092). Here I'm addressing two causes of them:
TaskRunWaiter
before it isconfirmed to be listening to the websocket. Using an
asyncio.Event
tosignal that the socket is actually connected before proceeding.
PrefectDistributedFuture
was waiting for task runs to complete, itwould ask the API if the task run was complete first, then go on to start
waiting. If the task changed state in-between those calls, it would likely
be missed entirely.
With these changes in place, I've run a large number of my test tasks (see
PrefectHQ/nebula#7962, which has a task with 5 layers of dependencies) at
TASKS=100
and have experienced no hangs. I did get a hang withTASKS=1000
,but this is a marked improvement from where we were before.
Part of #14098