Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[events executor] - Fix Behavior with Timer Cancel #2375
[events executor] - Fix Behavior with Timer Cancel #2375
Changes from 4 commits
c6608a4
11050a1
067271a
ac2005d
3a8e7e9
68ea151
0f20255
97a44fd
43fc22d
da1baa9
385c353
2fb28b9
666e9d5
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there's only 1 timer which is cancelled? Will we heap keep entering here at every iteration, without ever sleeping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent point - as-is, this would result in a busy loop as you suggest!
One possible fix would be to explicitly check the size of the heap and if it is 1, we can do a similar wait for
timers_updated_
. Any thoughts there? To me, that would result in a slightly messierrun_timers
method, but I don't know how else we would cleanly handle this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the single timer handling, but
run_timers
is getting a bit messy.Happy to refactor/reorganize it for clarity if you would like, just let me know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that the fix works.
What if there are more than 1 timers but they are all cancelled?
I think that the correct approach would likely require to:
a) remove cancelled timers from the heap
b) have a notification to put them back in when they are re-activated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, you are correct, this approach was brittle - sorry about that.
Will implement what you suggested here, thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alsora sorry for the delay here - had a busy couple of weeks.
@gusbrigantino and I refactored the code, and we came up with an implementation of
run_timers
that does not require storing cancelled timers and removing them from the heap. Rather, the approach is to try to re-heap if the head timer was cancelled, then re-organize some logic from that point on. If there are non-cancelled timers in the heap, then the re-heap will force them to be at the front and thus head is now valid and the logic remains the same. However, if all timers in the heap are cancelled, the behavior now matches the previous behavior with no timers in the heap -- we wait untiltimers_updated
istrue
.We added a few more test cases to validate a couple of different scenarios.
Please let us know if that makes sense and works for you!