Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timers wrong behavior #24362

Closed
twawszczak opened this issue Nov 14, 2018 · 2 comments
Closed

timers wrong behavior #24362

twawszczak opened this issue Nov 14, 2018 · 2 comments
Labels
confirmed-bug Issues with confirmed bugs. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

Comments

@twawszczak
Copy link

twawszczak commented Nov 14, 2018

  • Version: 11.1
  • Platform: Debian 7
  • Subsystem: timers

I have found another strange behavior of timers after refactor in v11. Example:

setTimeout(() => {
  console.log('firing', 11000)
}, 11000)

setTimeout(() => {
  console.log('firing', 90000)
}, 90000)

setInterval(() => {
  console.log('firing', 1000)
}, 1000)

const timer4000 = setTimeout(() => {
  console.log('firing', 4000)
}, 4000)

setTimeout(() => {
  console.log('firing', 60000)
}, 60000)

setTimeout(() => {
  console.log('firing', 100)

  const timer1500 = setTimeout(() => {
    console.log('firing', 1500)
  }, 1500)
  clearTimeout(timer1500)

}, 100)

setTimeout(() => {
  console.log('firing', 3000)
}, 3000)

clearTimeout(timer4000)

setTimeout(() => {
  console.log('firing', 16000)
}, 16000)

It is a bit complicated, but when i am removing any part, it works as expected. An output:

firing 100
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 11000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 16000
firing 1000
firing 1000
...

So, 3000ms timeout is never fired. There is a way to make that example to working a little different:

setTimeout(() => {
  console.log('firing', 11000)
}, 11000)

setTimeout(() => {
  console.log('firing', 90000)
}, 90000)

setInterval(() => {
  console.log('firing', 1000)
}, 1000)

const timer4000 = setTimeout(() => {
  console.log('firing', 4000)
}, 4000)

setTimeout(() => {
  console.log('firing', 60000)
}, 60000)

setTimeout(async () => {
  console.log('firing', 100)

  const timer1500 = setTimeout(() => {
    console.log('firing', 1500)
  }, 1500)
  await Promise.resolve()
  clearTimeout(timer1500)

}, 100)

setTimeout(() => {
  console.log('firing', 3000)
}, 3000)

clearTimeout(timer4000)

setTimeout(() => {
  console.log('firing', 16000)
}, 16000)

Then, output is:

firing 100
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 11000
firing 1000
firing 1000
firing 1000
firing 1000
firing 1000
firing 16000
firing 3000
firing 1000

So, 3000ms timer is unlocked, but only after 16000ms timer is fired. O_O

I suppose, it is related to that one, but works a little different, so i am making another issue. I am a bit angry, because i spend a few days to extract specific issue form whole, async app. :/

@benjamingr
Copy link
Member

Thanks for the report! cc @nodejs/timers @apapirovski

@starkwang starkwang added confirmed-bug Issues with confirmed bugs. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. labels Nov 14, 2018
Trott pushed a commit to Trott/io.js that referenced this issue Nov 15, 2018
PR-URL: nodejs#24322
Fixes: nodejs#24320
Fixes: nodejs#24362
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
@Trott
Copy link
Member

Trott commented Nov 15, 2018

Fixed in 9ca5c52

@Trott Trott closed this as completed Nov 15, 2018
BridgeAR pushed a commit that referenced this issue Nov 15, 2018
PR-URL: #24322
Fixes: #24320
Fixes: #24362
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants