This repository has been archived by the owner on May 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unix: update events from pevents between polls
Watchers could be stopped between two `kevent()`/`epoll_wait()` calls (which may happen in the same loop in `uv__io_poll()`), in such cases `watcher->events` could be stale and won't be updated to `watcher->pevents`. Try to use and rely on `watcher->pevents` instead of blindly expecting `watcher->events` to be always correct.
- Loading branch information
Showing
2 changed files
with
12 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { | |
uv__io_t* w; | ||
uint64_t base; | ||
uint64_t diff; | ||
unsigned int masked_events; | ||
int nevents; | ||
int count; | ||
int nfds; | ||
|
@@ -208,7 +209,15 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { | |
continue; | ||
} | ||
|
||
w->cb(loop, w, pe->events); | ||
/* | ||
* Give users only events they're interested in. Prevents spurious | ||
* callbacks when previous callback invocation in this loop has stopped | ||
* the current watcher. Also, filters out events that users has not | ||
* requested us to watch. | ||
*/ | ||
masked_events = pe->events & w->pevents; | ||
if (masked_events != 0) | ||
w->cb(loop, w, masked_events); | ||
nevents++; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bnoordhuis
Contributor
|
||
} | ||
|
||
|
I didn't spot this during review but there's a conceptual bug here. uv__io_poll() is only supposed to return when either:
a) the timeout expires, or
b) one or more callbacks have been made
nevents is used to keep track of b) - it's only supposed to get incremented when a callback is made. It's probably not very harmful but there's now a possibility of returning from uv__io_poll() when a) nor b) are true.