Timeout happening too early
See original GitHub issueI’m reporting the case from this SO question:
The following example times out in most cases (outputs
timed out
):Promise = require('bluebird'); new Promise(resolve => { setTimeout(resolve, 1000); }) .timeout(1001) .then(() => { console.log('finished'); }) .catch(error => { if (error instanceof Promise.TimeoutError) { console.log('timed out'); } else { console.log('other error'); } });
Does this mean that the Bluebird’s promise overhead takes longer than 1ms? I see it often time out even if I use
.timeout(1002)
.
Using Bluebird 3.5.0, under Node.js 8.1.2
I would expect this to never output timed out
, since the timeouts happen in order, and the latter with higher timespan value. Given that the promise chain resolution happens in the microtask queue, the fulfillment callback should log finished
before the macrotask timer callback from .timeout()
runs and even get a chance at cancelling the promise.
Is this a bug, or are my expectations off?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
asp.net - Why is my session timeout happening early?
The timeout attribute in sessionState allows you to set the time in minutes,and default timeout is 20 minutes.
Read more >Session expires too early - MSDN - Microsoft
It's running on a production server with other applications hosted on it too. Everything was fine unitll suddenly my asp application seems to...
Read more >Why does my application timeout, before the Session timeout ...
All of the timeouts in the application are set to reasonable values, so why does the browser session time out early.
Read more >Taking a Timeout from Poor Performance | APIs You Won't Hate
Making timeouts happen early is much more important than getting a fast failure. The most important benefit of failing fast is to give...
Read more >What is Time-Out? | Essentials | Parenting Information - CDC
Time-out is when your child is removed from where the misbehavior happened. Your child is away from all things that are fun.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sanji-programmer Node timers are not accurate to the millisecond fwiw. There is an open bug for that I can hunt it if it’s important to you.
I can confirm that the fix 892286b can avoid the race reported by @bergus; I could reproduce the race with a tool I’ve worked with to test different schedules of the event loop.
Nevertheless, if we do the opposite:
the race remains with this code giving ‘time out’ or ‘finished’ based on the status of event loop.
It seems that, at least in Node, callback
timeout()
in this code and callbacktimeoutTimeout()
in timers.js are registered in the same tick of event loop; so some order between them can be defined. The issue may be thatthis.drainQueues()
(line 16 of async.js) is registered usingsetImmediate()
and it can race with the other timeout callbacks.