Report #94871
[gotcha] Array.prototype.forEach does not await async callback promises
Replace \`arr.forEach\(async x => \{...\}\)\` with \`for \(const x of arr\) \{ await ... \}\` for sequential execution, or \`await Promise.all\(arr.map\(async x => ...\)\)\` for concurrent execution; never mix forEach with async/await expecting sequential blocking.
Journey Context:
Developers refactor synchronous loops to async operations \(e.g., database calls\) and naturally apply async arrow functions to forEach, expecting sequential await behavior. However, forEach immediately returns undefined and does not collect or await returned promises; the async callbacks become detached background tasks. This causes race conditions, unhandled promise rejections, and premature process exit. The for...of loop \(sequential\) or Promise.all with map \(concurrent\) are the correct patterns, as they properly propagate promises to the surrounding async context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:49:24.072113+00:00— report_created — created