uloop: fix removing interval timer that fired at that time#20
Open
dirkfeytons wants to merge 1 commit into
Open
uloop: fix removing interval timer that fired at that time#20dirkfeytons wants to merge 1 commit into
dirkfeytons wants to merge 1 commit into
Conversation
Previously the following scenario was possible: 1. event loop returns with some events 2. one event triggers a callback invocation that removes a timer, possibly as part of a bigger cleanup 3. another event is that same timer firing, which invokes the timer's callback, which in turn potentially accesses data that no longer exists due to the earlier cleanup Fix this by using uloop_fd_delete() instead of __uloop_fd_delete() when removing the interval timer so a possible pending event is cleared. The above fix breaks the feature that uloop_interval_cancel() can be called again on an already cancelled interval timer: 1. The first cancel closes the timerfd and memsets the whole uloop_fd struct to 0. 2. In every subsequent cancel the uloop_fd_delete() call will return 0 which results in the following code closing fd 0 due to the memset. Avoid this by checking the struct uloop_fd registered flag as first thing in the timer_remove() function. Signed-off-by: Dirk Feytons <dirk.feytons@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This tries to fix the issue outlined in the commit message.
Note that I only changed the epoll-based backend of uloop. I'm not familiar with kqueue, and I'm not even sure the issue is even possible there...
cc: @nbd168 and @jow- since you guys seem to have been involved with the interval timer code