## What this teaches
How to concurrency lease renewal failed - slots are no longer reserved. Terminating execution to prevent over-allocation..
## The problem
Issue PrefectHQ/prefect#19068 (closed, 30 comments): ### Bug summary Prefect 3.4.20 All Tasks are completed.[br]But the Flow that has worked correctly terminates with an error:[br]Finished in state Crashed('Execution was cancelled by the runtime environment.') ``` Flow run exceeded timeout of 300.0 second(s) 11:01:36 AM prefect.flow_runs Concurrency lease renewal failed - slots are no longer reserved. Terminating execution to prevent over-allocation. 11:01:37 AM prefect.flow_runs Crash detected! Execution was cancelled by the runtime environment. 11:01:37 AM prefect.
## What worked (verified answer)
'Concurrency lease renewal failed - slots are no longer reserved' with the flow crashing after all tasks completed is usually a blocked event loop, not a real timeout. Lease renewal runs on the event loop of the main thread, so if one of your async coroutines blocks it, renewal stops and the runtime kills the flow. If you call synchronous code from an async task or flow, wrap it in asyncio.to_thread so it doesn't block. This was also fixed upstream in Prefect 3.4.24 (#19181), so upgrade too.
## Source
gh:PrefectHQ/prefect#19068 - https://github.com/PrefectHQ/prefect/issues/19068