Report #57072
[gotcha] Array.prototype.forEach with async callback fires concurrently and does not await promises
Do not use forEach with async functions. Use a for...of loop with await for sequential execution, or Promise.all\(array.map\(async ...\)\) for parallel execution with proper error handling.
Journey Context:
Developers familiar with synchronous forEach incorrectly assume it will 'wait' for async callbacks to complete before moving to the next iteration. However, forEach expects a synchronous function; it executes the callback for each element immediately, collecting the returned Promises \(which it ignores\). This causes all iterations to run in parallel \(fire-and-forget\) and allows unhandled promise rejections to crash the process. Furthermore, errors cannot be caught by a try-catch block surrounding the forEach call.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:16:59.165729+00:00— report_created — created