r/node • u/ethlmao • Jan 19 '26
I built a tiny Node.js utility to enforce end-to-end async deadlines (not just promise timeouts)
Hey folks 👋
I ran into a recurring issue in Node services:
timeouts usually wrap one promise, but real request flows span multiple async layers — DB calls, HTTP calls, background work — and timeouts silently break down.
So I built a small utility called safe-timeouts that enforces a deadline across an entire async execution, not just a single promise.
Key ideas:
• Deadline-based timeouts (shared across nested async calls)
• Uses AsyncLocalStorage to propagate context
• Cancels work using AbortController when supported
• Optional Axios helper so you don’t have to pass signal everywhereIf the deadline is exceeded anywhere in the flow, execution stops and cancellable work is aborted.
It’s intentionally small and boring — meant to be a primitive, not a framework.
Repo / NPM
https://github.com/yetanotheraryan/safe-timeouts
https://www.npmjs.com/package/safe-timeouts
Would genuinely love feedback from people who’ve dealt with:
• hung requests
• axios continuing after timeouts
• messy Promise.race usage
• passing AbortSignal through too many layersHappy to learn what feels useful or awkward 🙏
4
u/bwainfweeze Jan 19 '26
This probably deserves some benchmarks. And tests. It’d be good for people to know what speed they are trading off for accuracy. So they can make decisions about how much time they are saving for how much it’s costing them.
3
u/czlowiek4888 Jan 19 '26
So you basically want to automatically wrap every 'await' keyboard automatically in a promise.race?
So you can create a function called tryInTime(func, ...params).
It throws error if didn't return response on time.
The problem is that you need to have a reference to a promise resolver function...
Hmm, what about overriding base Promise object to make it use AsyncLocalStorage to store reference for a resolver when promise starts to execute. This way you will be able to override resolver with empty function stopping execution.
25
u/blinger44 Jan 19 '26
AI out here solving all sort of problems I’ve never had