Note 19 / Node.js / Backend / NestJS
Three small ways a Node backend dies or never exits: void async callbacks, a side read inside Promise.all, and ioredis quit()
A void async call in a socket callback, an optional Redis read inside Promise.all, and quit() on a client with no offline queue. Each one was a process-level failure from a database or Redis hiccup.
- By
- Trần Thế Anh, Software Engineer
- Published
- Work done
- October 2026, AI Note Taker (NestJS, Node.js, ioredis 6, Postgres)
- Stack
- Node.js, NestJS, ioredis 6, Prisma, Jest
- Reading
- 7 min, 1,505 words
These three bugs have little in common except where they live: at the edge of a request or a lifecycle, where a short Postgres or Redis outage turns into something much larger than a failed request. One killed the API process, one turned a note-detail screen into a 500, and one made the process refuse to exit during shutdown. All three came out of one hardening pass over a NestJS meeting-notes backend in October 2026.
void doThing() inside a socket callback
The backend receives Zoom’s real-time media stream over a WebSocket. The client wrapper takes callbacks: onActive, onEnded, onError. Two of them did this:
onEnded: (reason) => {
clients.delete(streamId);
void this.finishSession(session, reason);
},
void here means “I am deliberately not awaiting this”. It does not mean “errors are handled”. finishSession ends by writing the session’s final state to the database. When that write fails, the async function rejects, nobody is attached to the promise, and Node reports an unhandled rejection.
What Node does with it is a documented default. The process documentation says an 'unhandledRejection' event that is not handled is raised as an uncaught exception, and that throw is the default mode of the --unhandled-rejections flag. An uncaught exception ends the process. I confirmed the behaviour in isolation on Node 26.13.0:
const finish = async () => { throw new Error("db hiccup"); };
setTimeout(() => { void finish(); }, 10);
setTimeout(() => console.log("still alive"), 200);
Error: db hiccup
at finish (voidrej.js:1:36)
Node.js v26.13.0
exit=1
“still alive” is never printed. Adding process.on("unhandledRejection", ...) keeps the process alive and prints the logged line instead, with exit 0.
That second line matters for how I describe my own bug. This backend also installs a last-resort listener (one line at API start-up and one in the worker) that logs every unhandled rejection with its stack and the process name. So in the current tree a database blip in these callbacks would be logged, not fatal. I do not have the order in which that listener and this fix landed, so I cannot tell you the API was ever killed in production by this path. What I can say from the code is that even with the safety net, the write that moves the bot session to its final state is lost when the database call fails. The net says “an error happened somewhere”; it cannot repair the half-finished work. The lesson in my log is written about the process-level danger; read it as the worst case, not a measured outage.
The rule I applied: a function that is called without await, or from a callback, owns all of its errors, including the error from its own error handler.
async onStopped(...) : Promise<void> {
try {
await this.handleStopped(...);
} catch (error) {
this.logger.error(`stop failed: ${(error as Error).message}`);
}
}
private async safeMarkFailed(session, reason) {
try { await this.markFailed(session, reason); }
catch (e) { this.logger.error(`could not write FAILED: ${(e as Error).message}`); }
}
The second function is the point people skip. The catch block of a callback usually does a write (“mark the session failed”), and if the database is the thing that is down, that write rejects too. A catch that can throw is a second unhandled rejection. So the failure write gets its own non-throwing wrapper.
A related leak sat in the start path. Constructing the WebSocket client can throw synchronously (a malformed signalling URL throws a SyntaxError). By then the code had already registered the client in a map and opened a paid speech-to-text session, so a throw there left both behind, and the retry webhook was ignored as “already connected”. The fix wraps the construction and cleans up what was registered before rethrowing.
The test I trust is the one that listens for the event instead of asserting on the logger: it adds a process.on("unhandledRejection") listener, forces the database mock to reject, calls the callbacks, waits a tick, and checks the listener saw nothing. Six cases cover it, and the reviewer’s deliberate breakages (removing the catch, letting the failure write throw) turned them red.
My sweep, grep -rnE "^\s*void this\.[a-zA-Z.]+\(" src | grep -v spec.ts, returned 15 call sites. Three of them (an admin event publish, a meeting-events send and a heartbeat) already caught their own errors. Two were the Zoom ones above, and finishSession no longer rejects.
One failing side read inside Promise.all
The second bug is dull and the most common of the three. The note-detail endpoint returns the stored artifacts (mind map, quiz, and so on) and a status telling the app whether a generation job is currently running:
const [artifact, touchedAt, job] = await Promise.all([
db.artifact.findFirst(...),
this.sourceTouchedAt(id),
this.pipeline.artifactJobState(id, kind), // reads Redis
]);
Promise.all rejects with the first rejection. When Redis hiccuped, the status read failed and the whole endpoint returned 500, although the artifact itself sat in Postgres and could have been returned. The user could not open the screen because a progress indicator could not be fetched.
Here it is in thirty lines of Node, same version as above:
Promise.all -> redis down
with catch -> [ 'payload', 'unknown' ]
The fix is to make the optional read unable to fail the required one. The service wraps the Redis read, logs a warning, and returns 'unknown', a state the response type already allows:
private async jobState(id: number, kind: ArtifactKind) {
try {
return await this.pipeline.artifactJobState(id, kind);
} catch (error) {
this.logger.warn(`job state failed for ${id}/${kind}: ${(error as Error).message}`);
return "unknown";
}
}
The test is a case where the Redis call throws, and the assertion is that the endpoint still returns the artifact. The sweep here was by hand: The log records a hand check of every Promise.all in the artifact service and the pipeline producer, and the secondary reads there have a catch. That is a weaker check than a command, and I say so in the log. The rule is to classify each member of a Promise.all as required or optional, and an optional member degrades to “unknown” without throwing. If you use Promise.allSettled, you still have to decide what an unfulfilled optional value means to the caller.
quit() on a client that cannot queue
The third is a shutdown hang. Two ioredis clients in the backend (the rate-limit storage and a session-state service) are created with enableOfflineQueue: false, because a rate limiter should fail fast instead of piling commands up while Redis is slow. On module destroy the code called await redis.quit(), the polite way to close.
An integration test hung for more than ten minutes, and I traced it to this. With Redis unreachable at shutdown the process would not exit either. The reason is in ioredis 6.0.0. In sendCommand, when the stream is not writable and the offline queue is off, the command is rejected immediately. A branch further down says that quit with an empty offline queue should call disconnect() and resolve, but the rejection comes first, so it is never reached. The reconnect loop keeps running and keeps the event loop alive.
I reproduced it with ioredis 6.0.0 (installed in another project of mine; the backend’s package.json asks for ^6.0.0), a client pointed at a closed port, and the same options:
quit rejected: Stream isn't writeable and enableOfflineQueue options is false
quit status= reconnecting reconnects after close: 2
disconnect status= reconnecting reconnects after close: 0
After quit() the client went on reconnecting, twice in three seconds. After disconnect() it did not reconnect at all. Note that status reads reconnecting in both cases, which is why the test counts reconnecting events after the call and does not look at status. The ioredis README says automatic reconnection does not happen when the connection was closed manually with disconnect() or quit(). In this configuration quit() never gets to close anything, because the command is rejected before it is sent, so the reconnect loop is still running.
So the two clients now use disconnect() in onModuleDestroy. A rate limiter has nothing to flush at shutdown. The other .quit() calls in the codebase at the time belong to clients with the default offline queue, where ioredis turns quit into disconnect itself when the connection is down, and I left them.
What I did not verify
The lessons entries for the callback bug (BL-259) and the Redis shutdown (BL-093) were marked fixed before their commits landed when I wrote them up; the side-read fix (BL-250) is at commit 05e66bd and deployed. I ran the isolated scripts above in this session, but not the backend’s Jest suites. The suite results come from my lessons log. And as said above, I have no production log showing the API dying from the callback bug.
Sources
- Node.js process events: an unhandled
'unhandledRejection'is raised as an uncaught exception;throwis the default mode. - ioredis README: offline queue and the reconnection note.
- ioredis 6.0.0
built/Redis.js,sendCommand: order of the offline-queue rejection and thequitbranch, read in the installed package.