Report #46954
[gotcha] Array.prototype.forEach with async callback fires-and-forgets promises causing race conditions
Use for...of loops with await for sequential async iteration, or Promise.all\(array.map\(async fn\)\) for parallel execution; never use forEach with async functions
Journey Context:
forEach expects synchronous callbacks; it executes the callback for each element immediately, collecting return values \(Promises\) which it ignores. It does not await the async operations and does not propagate errors. Errors in the async callback become unhandled promise rejections rather than thrown exceptions, and execution order becomes non-deterministic. Developers often refactor working sequential for-await loops into "cleaner" forEach one-liners during code review, inadvertently introducing race conditions and swallowed errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:17:07.281505+00:00— report_created — created