-
Notifications
You must be signed in to change notification settings - Fork 703
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
[BUG] inconsistent behavior of kqueue aeApiDelEvent comparing to the code before #638 #715
Comments
thanks, this looks reasonable, please make a PR so that we can do a review |
I looked into the related code before submitting a PR, and found that the This is the first commit to
Then in 2014, a small commit moves Also I believe both I'll submit the PR with all the above fixes I would like to make, which is still very small. |
…DelEvent (#725) for kqueue: EV_DELETE fails if the specified fd is not associated with the kqfd. If EVFILT_WRITE is associated but EVFILT_READ is not, then calling aeApiDelEvent with mask = -1 or `(AE_READABLE|AE_WRITABLE)` will cause the kevent() to fail with errno = 2(No such file or directory) and EVFILT_WRITE not dissociated. So we need to calculate the actual mask to be removed, instead of passing in whatever user provides. for evport: The comment clearly states that aeApiDelEvent "rely on the fact that our caller has already updated the mask in the eventLoop". for epoll: There's no need to calculate the "actual mask" twice, once in `aeDeleteFileEvent` and another in `aeApiDelEvent`, let's just use the mask recorded in the eventLoop. Fixes #715 Signed-off-by: wkgcass <[email protected]> Co-authored-by: Andy Pan <[email protected]> Co-authored-by: Binbin <[email protected]>
…DelEvent (valkey-io#725) for kqueue: EV_DELETE fails if the specified fd is not associated with the kqfd. If EVFILT_WRITE is associated but EVFILT_READ is not, then calling aeApiDelEvent with mask = -1 or `(AE_READABLE|AE_WRITABLE)` will cause the kevent() to fail with errno = 2(No such file or directory) and EVFILT_WRITE not dissociated. So we need to calculate the actual mask to be removed, instead of passing in whatever user provides. for evport: The comment clearly states that aeApiDelEvent "rely on the fact that our caller has already updated the mask in the eventLoop". for epoll: There's no need to calculate the "actual mask" twice, once in `aeDeleteFileEvent` and another in `aeApiDelEvent`, let's just use the mask recorded in the eventLoop. Fixes valkey-io#715 Signed-off-by: wkgcass <[email protected]> Co-authored-by: Andy Pan <[email protected]> Co-authored-by: Binbin <[email protected]> Signed-off-by: hwware <[email protected]>
…DelEvent (valkey-io#725) for kqueue: EV_DELETE fails if the specified fd is not associated with the kqfd. If EVFILT_WRITE is associated but EVFILT_READ is not, then calling aeApiDelEvent with mask = -1 or `(AE_READABLE|AE_WRITABLE)` will cause the kevent() to fail with errno = 2(No such file or directory) and EVFILT_WRITE not dissociated. So we need to calculate the actual mask to be removed, instead of passing in whatever user provides. for evport: The comment clearly states that aeApiDelEvent "rely on the fact that our caller has already updated the mask in the eventLoop". for epoll: There's no need to calculate the "actual mask" twice, once in `aeDeleteFileEvent` and another in `aeApiDelEvent`, let's just use the mask recorded in the eventLoop. Fixes valkey-io#715 Signed-off-by: wkgcass <[email protected]> Co-authored-by: Andy Pan <[email protected]> Co-authored-by: Binbin <[email protected]> Signed-off-by: hwware <[email protected]>
…DelEvent (valkey-io#725) for kqueue: EV_DELETE fails if the specified fd is not associated with the kqfd. If EVFILT_WRITE is associated but EVFILT_READ is not, then calling aeApiDelEvent with mask = -1 or `(AE_READABLE|AE_WRITABLE)` will cause the kevent() to fail with errno = 2(No such file or directory) and EVFILT_WRITE not dissociated. So we need to calculate the actual mask to be removed, instead of passing in whatever user provides. for evport: The comment clearly states that aeApiDelEvent "rely on the fact that our caller has already updated the mask in the eventLoop". for epoll: There's no need to calculate the "actual mask" twice, once in `aeDeleteFileEvent` and another in `aeApiDelEvent`, let's just use the mask recorded in the eventLoop. Fixes valkey-io#715 Signed-off-by: wkgcass <[email protected]> Co-authored-by: Andy Pan <[email protected]> Co-authored-by: Binbin <[email protected]> Signed-off-by: hwware <[email protected]>
…DelEvent (valkey-io#725) for kqueue: EV_DELETE fails if the specified fd is not associated with the kqfd. If EVFILT_WRITE is associated but EVFILT_READ is not, then calling aeApiDelEvent with mask = -1 or `(AE_READABLE|AE_WRITABLE)` will cause the kevent() to fail with errno = 2(No such file or directory) and EVFILT_WRITE not dissociated. So we need to calculate the actual mask to be removed, instead of passing in whatever user provides. for evport: The comment clearly states that aeApiDelEvent "rely on the fact that our caller has already updated the mask in the eventLoop". for epoll: There's no need to calculate the "actual mask" twice, once in `aeDeleteFileEvent` and another in `aeApiDelEvent`, let's just use the mask recorded in the eventLoop. Fixes valkey-io#715 Signed-off-by: wkgcass <[email protected]> Co-authored-by: Andy Pan <[email protected]> Co-authored-by: Binbin <[email protected]>
Describe the bug
If
writable
is registered into the kqueue andreadable
is not,aeDeleteFileEvent
will fail if the mask isAE_READABLE | AE_WRITABLE
or simply-1
Tested on
macOS Ventura 13.6.7, x86_64
.To reproduce
AE_WRITABLE
events usingaeCreateFileEvent
aeDeleteFileEvent
withmask = -1
writable
event still firesExpected behavior
The
writable
event should not fire after callingaeDeleteFileEvent
withmask = -1
Additional information
This is related to #638
The current
ae_kqueue#aeApiDelEvent
uses a singlekevent
to remove bothreadable
andwritable
events with a single syscall,but unlike
EV_ADD
, theEV_DELETE
fails if theEVFILT_xxx
is not previously registered intokqueue
.If
EVFILT_READ
is not registered, thekevent
will fail andEVFILT_WRITE
will not be deleted.This behavior can be verified by the following simple code snippet:
The output would be:
This can be easily fixed, just modify the mask
mask = mask & fe->mask
before callingaeApiDelEvent
.I'm willing to submit a PR if this is desired.
The text was updated successfully, but these errors were encountered: