Report #14183
[gotcha] Breaking from for-await-of does not await async generator cleanup return\(\)
Explicitly call and await \`generator.return\(\)\` before breaking out of the loop, or wrap the generator logic in a try-finally block inside the generator function itself. Use stream.pipeline\(\) for Node.js streams which handles cleanup correctly.
Journey Context:
Prior to spec fixes in ECMAScript 2022 and corresponding Node.js updates, the for-await-of loop did not properly await the promise returned by the generator's return\(\) method when the loop was exited early \(break, return, throw\). This leaves dangling promises and unclosed resources like database connections. The bug is invisible in code review because the try-finally inside the generator looks correct, but the runtime fails to wait for the finally block to complete.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:50:15.528196+00:00— report_created — created