-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Phantom event callbacks with EV_ET #984
Description
In Envoy today, we sometimes have network socket FDs setup with event_assign to watch for EV_CLOSED | EV_ET | EV_PERSIST. The callback function is invoked on EV_READ or EV_WRITE however, as a result of the following call chain:
-
epoll_dispatchissuing read/write events withEV_ETset, see.Line 504 in 0d2f170
evmap_io_active_(base, events[i].data.fd, ev | EV_ET); -
evmap_io_activemasking outEV_READandEV_WRITE(since we're only looking forEV_CLOSED) but preservingEV_ETin.Line 436 in 0d2f170
event_active_nolock_(ev, ev->ev_events & events, 1); -
event_active_nolock_delivering an event to the callback withresset toEV_ET, despite no registered event actually firing.
This can be fixed with the following patch:
diff --git a/evmap.c b/evmap.c
index ffc991f5..d824c062 100644
--- a/evmap.c
+++ b/evmap.c
@@ -432,7 +432,7 @@ evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events)
if (NULL == ctx)
return;
LIST_FOREACH(ev, &ctx->events, ev_io_next) {
- if (ev->ev_events & events)
+ if (ev->ev_events & (events & (EV_READ | EV_WRITE | EV_CLOSED)))
event_active_nolock_(ev, ev->ev_events & events, 1);
}
}
I'm wondering if folks agree that this is a bug and whether the above patch is the correct fix?
CC @asraa @adisuissa