An HTTP request that hangs forever, no response, nothing in the logs, no process crash: that's the most confusing symptom of a mishandled async error in Node.js. Something failed somewhere, but the failure never turned into an error response or a usable trace. This isn't a rare edge case; it's the default behavior of several very common async patterns, and understanding why saves hours of debugging with randomly scattered console.log calls.
The mechanism: a rejected promise nobody is listening to
When an async function throws, it doesn't throw in the synchronous sense: it returns a rejected promise. If nothing attaches a .catch() to that promise (or awaits it inside a try/catch), the rejection becomes an "unhandled rejection". Since Node.js 15, the default behavior for an unhandled rejection is to terminate the process (before that, Node just logged a warning), which is at least visible outside of Express. The problem gets worse in a context where the framework itself swallows the promise without watching it.
Express 4 (and earlier) is the most common example: a route handler declared async that throws doesn't automatically forward that error to Express's error-handling middleware.
// Express 4: this handler leaks silently
app.get('/orders/:id', async (req, res) => {
const order = await orderService.findById(req.params.id); // if this rejects...
res.json(order);
});
If findById rejects, Express 4 has no idea the function is asynchronous: it already returned control after the synchronous call to the handler. The rejected promise goes nowhere, res.json never runs, the client hangs until it times out, and depending on configuration, nothing gets logged beyond maybe a process-level unhandledRejection warning with no obvious link to the request that caused it.
Diagnosing: where to look for the leak
The typical symptom is a client-side timeout with no trace on the server. Points to check systematically:
- An
asyncroute handler with no error-capturing wrapper (Express 4 and earlier). - A
.forEach()with anasynccallback:forEachnever awaits any promise, so an error inside the callback becomes an unhandled rejection detached from any request context. - An
EventEmitterlistener declaredasync:emitter.emit()never propagates an error coming from an async listener, it goes straight to an unhandled rejection. - A fire-and-forget call: an async function invoked without
awaitor.catch(), often to "avoid blocking" a secondary task (sending an email, writing an audit log).
// forEach: every error becomes an isolated unhandled rejection
items.forEach(async (item) => {
await processItem(item); // if this rejects, nobody finds out in the right context
});
// fire-and-forget with no safety net
sendAuditLog(userId, action); // async function called without await or catch
Adding global listeners at least makes the invisible visible, as a last resort:
process.on('unhandledRejection', (reason, promise) => {
logger.error('Unhandled rejection', { reason });
});
process.on('uncaughtException', (err) => {
logger.error('Uncaught exception, shutting down', { err });
process.exit(1); // the process may be in a corrupted state, don't keep it alive
});
These two listeners are a safety net, not a strategy: they prevent losing the trace in production, but they don't stop the original HTTP request from hanging, since they have no idea which response to send, or to whom.
The fix: close every async boundary
The structural fix is to guarantee that no rejected promise can exist without a .catch() or a try/catch that explicitly ties it to a context, such as the current HTTP request.
For Express 4 routes, a generic wrapper fixes the problem at the source:
const asyncHandler = (fn) => (req, res, next) => {
Promise.resolve(fn(req, res, next)).catch(next);
};
app.get('/orders/:id', asyncHandler(async (req, res) => {
const order = await orderService.findById(req.params.id);
res.json(order);
}));
next(err) forwards the error to Express's error-handling middleware, which can finally respond with an appropriate HTTP status and message. The express-async-errors package applies this patch transparently to every route without rewriting each handler by hand. Worth noting: Express 5 fixes this natively, a rejecting async handler is automatically forwarded to next(), making this wrapper unnecessary on that version.
For iteration, replace forEach with a for...of loop using await, or with Promise.all when the work can run concurrently and one failing item should fail the whole batch:
// Sequential, every error propagates normally
for (const item of items) {
await processItem(item);
}
// Concurrent, but a single error fails the whole batch
await Promise.all(items.map((item) => processItem(item)));
// Concurrent, and each item's outcome matters independently
const results = await Promise.allSettled(items.map((item) => processItem(item)));
const failures = results.filter((r) => r.status === 'rejected');
For EventEmitter listeners, systematically wrap the async body in a local try/catch:
emitter.on('order.created', async (order) => {
try {
await notifyWarehouse(order);
} catch (err) {
logger.error('Failed to notify warehouse', { orderId: order.id, err });
}
});
The Promise constructor trap
Another less-known leak point hides inside the new Promise((resolve, reject) => { ... }) constructor when the code inside is itself asynchronous. An error thrown synchronously in the executor gets captured correctly and turned into a rejection, but an error thrown from a nested asynchronous callback (a setTimeout, a second .then() not wired to reject) escapes as an uncaught exception, completely disconnected from the promise it was supposed to settle:
// Trap: an error inside setTimeout never becomes a rejection of the promise
function delayedFetch(id) {
return new Promise((resolve, reject) => {
setTimeout(() => {
const data = riskyParse(id); // if this throws, neither resolve nor reject is called
resolve(data);
}, 100);
});
}
// Fix: capture explicitly and call reject
function delayedFetch(id) {
return new Promise((resolve, reject) => {
setTimeout(() => {
try {
resolve(riskyParse(id));
} catch (err) {
reject(err);
}
}, 100);
});
}
In most cases this pattern isn't even needed: wrapping an already promise-based async API inside new Promise() is redundant, a well-known anti-pattern sometimes called the "Promise constructor antipattern". The Promise constructor should only be used to wrap a callback-based API that doesn't natively expose a promise, never to delay or recompose code that's already async/await.
Promises that never settle at all
Not every leak comes from an uncaught error: some come from a promise that never resolves or rejects, because the underlying operation (a network call to a slow service, a connection that stops responding) has no defined deadline. The original HTTP request then hangs indefinitely, with nothing to log since it isn't technically a rejection, just an absence of resolution. AbortController bounds this kind of call in time and turns an infinite wait into a usable error:
async function fetchWithTimeout(url, timeoutMs = 5000) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
try {
const res = await fetch(url, { signal: controller.signal });
return await res.json();
} finally {
clearTimeout(timer);
}
}
With this wrapper, a remote service that never responds produces an AbortError that the route's try/catch or asyncHandler can capture, instead of leaving the client's request hanging until the proxy's or browser's own timeout kicks in, with no usable trace on the server side.
The tradeoffs
Applying an asyncHandler wrapper everywhere, or migrating to Express 5, forces a systematic review of every existing route, which isn't free on a sizeable codebase. Global unhandledRejection/uncaughtException listeners give a false sense of safety when treated as the solution rather than a last-resort net: they never send the right HTTP response to the right client, they just flag that something went wrong, after the fact.
When it isn't enough
Closing every async boundary eliminates the silent leak, but doesn't fix the underlying problem if the error itself is misclassified: returning a generic 500 for a business validation error, or logging an expected outcome (resource not found) at the same severity as a real outage, drowns real signals in noise. The error-capturing net needs to be paired with an explicit error hierarchy (business errors vs. technical errors) so monitoring can tell a legitimate 404 apart from an external dependency that's genuinely down.
Takeaway
A rejected promise with no .catch() and no await inside a try/catch disappears silently in Express 4, forEach, and EventEmitter listeners: this isn't an occasional bug but a structural property of all three patterns. The durable fix is making sure no async boundary is left open, using asyncHandler or Express 5 on the routing side, for...of/Promise.all for iteration, and a local try/catch inside every event listener.
