Challenge 1: Find and Fix a Listener Leak — Possible Solution ==================================================================== BEFORE (leaks a listener — and everything it closes over — on every request): app.get("/dashboard", (req, res) => { bus.on("order.placed", (payload) => { res.write(JSON.stringify(payload)); }); // res is never released from the bus's listener list — after 10,000 // requests, 10,000 dead `res` objects (and their sockets) are still // referenced and cannot be garbage collected. }); AFTER (unsubscribes once the response finishes): app.get("/dashboard", (req, res) => { const onOrderPlaced = (payload: { orderId: string; total: number }) => { res.write(JSON.stringify(payload)); }; bus.on("order.placed", onOrderPlaced); res.on("finish", () => { bus.off("order.placed", onOrderPlaced); }); // Also handle the client disconnecting early, which doesn't always fire "finish": res.on("close", () => { bus.off("order.placed", onOrderPlaced); }); }); WHY THIS WORKS -------------- - The listener is stored in a named variable (onOrderPlaced) instead of an inline arrow function, because bus.off() needs a reference to the exact same function that was passed to bus.on() — an inline arrow function passed separately to off() would never match and the listener would never actually be removed. - Listening for both "finish" (normal completion) and "close" (client disconnected early) ensures the listener is cleaned up in either case — relying on "finish" alone would leak a listener for every request whose client disconnects before the response completes. - After this fix, each request's listener has a lifetime exactly matching that request's lifetime — nothing outlives the request that created it.