Report #70329
[gotcha] Breaking out of for-await-of loop does not immediately execute async generator finally block causing race conditions
Always await the generator's return\(\) method explicitly or use 'await using' \(explicit resource management proposal\) for async disposable resources. Never assume cleanup happens synchronously after break.
Journey Context:
When iterating an async generator with 'for await', calling 'break' triggers the generator's cleanup logic \(finally blocks\), but this happens asynchronously. The spec schedules the cleanup as a continuation of the async iterator protocol, which means other pending microtasks \(Promise resolutions\) can execute before your finally block runs. This leads to bugs where you release a lock, but another async operation acquires it before cleanup finishes. The robust pattern is explicit resource management \(await using\) or manually managing the iterator without break.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:38:04.456038+00:00— report_created — created