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

lib: fix - invalid timer priority queue order #24318

Closed
wants to merge 2 commits into from

Conversation

mareksrom
Copy link

  • in lib/timers.js PriorityQueue.percolateDown cannot be used for rescheduling list,
    because it does not work in all cases

    • updated item does not have to be root of the heap when new timers are created
      in runNextTicks and then percolateDown does not solve all binary heap
      inconsistencies
    • old behavior could cause infinite loop timers in some cases
  • added PriorityQueue.updateAt and PriorityQueue.update methods

    • simple implementation by remove & insert, could be improved...
    • rescheduling list uses updateAt method
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

- in lib/timers.js PriorityQueue.percolateDown cannot be used for rescheduling list,
  because it does not work in all cases
  - updated item does not have to be root of the heap when new timers are created
    in runNextTicks and then percolateDown does not solve all binary heap
    inconsistencies
  - old behavior could cause infinite loop timers in some cases

- added PriorityQueue.updateAt and PriorityQueue.update methods
  - simple implementation by remove & insert, could be improved...
  - rescheduling list uses updateAt method
@nodejs-github-bot nodejs-github-bot added the timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. label Nov 12, 2018
@mareksrom
Copy link
Author

Thanks for info, I’ll check the priority queue for your test case...

@mareksrom
Copy link
Author

The fix is still not complete, PriorityQueue.percolateDown is not suitable method for restoring binary heap after removal of item. I have to implement updateAt method without removing and inserting the item, that wil be able to fix binary heap up and also down... It will be used in updateAt and also removeAt methods...

@apapirovski
Copy link
Member

apapirovski commented Nov 12, 2018

@mareksrom sorry, I didn't see your PR earlier but I opened the correct version at #24322 which rebalances both up & down the heap. Would appreciate your review if you've got a moment.

@Fishrock123
Copy link
Contributor

Superseded by the now merged #24322

@mareksrom Thanks for making this anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants