Report #54113
[gotcha] for-await-of on EventEmitter hangs indefinitely or swallows errors due to missing Symbol.asyncIterator
Do not use for-await-of directly on EventEmitter or streams. Instead, use \`events.on\(emitter, 'eventName'\)\` from the Node.js events module, which returns a SafeAsyncIterator that properly handles backpressure, error events, and cleanup.
Journey Context:
EventEmitter is not natively an async iterable. Attempting to use for-await-of on it either fails immediately or hangs because the protocol isn't implemented. Even with streams, raw for-await-of doesn't handle the 'error' event, causing unhandled exceptions to crash the process. The 'events.on\(\)' helper was specifically added to Node.js to bridge this gap safely, creating an AsyncIterable that auto-cleans up listeners and propagates errors as rejections.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T21:19:33.108020+00:00— report_created — created