Skip to content

Commit

Permalink
lib: Correctly handle ppoll pfds.events == 0
Browse files Browse the repository at this point in the history
The frrevent system is spitting out this message in bgpd:
20:40:15 mem1-roc-f2-b1-r5-t2-d4 bgpd[13166]: [XETTR-D5MR0][EC 100663316] Attempting to process an I/O event but for fd: 214(8) no thread to handle this!

This is because as each io event is processed, it is possible that a
.events is set to 0.  This can leave a situation where we ask
ppoll to handle anything that happens on a fd with a .events of 0,
in this situation ppoll can return POLLERR, which indicates that
something bad has happened on the fd.

Let's cleanup the pfds after io events are handled that can be
cleaned up.

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Oct 8, 2024
1 parent c10e4d3 commit 89f974a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,35 @@ static void thread_process_io(struct event_loop *m, unsigned int num)
for (i = 0; i < last_read && ready < num; ++i)
thread_process_io_inner_loop(m, num, pfds, &i, &ready);

/*
* At this point any fd's that were processed
* have possibly had their .events == 0
* so we should remove them now from the list
* in it's entirety. This is being done
* because if we leave a fd in the poll even
* with a .events of 0, if the fd is closed
* poll will return a .revents of POLLERR
* This is not desirable, as that we are attempting
* to handle something we have absolutely no
* way to handle it at all.
*/
i = 0;
while (i < m->handler.pfdcount) {
if (m->handler.pfds[i].events != 0) {
i++;
} else {
memmove(m->handler.pfds + i, m->handler.pfds + i + 1,
(m->handler.pfdcount - i - 1) * sizeof(struct pollfd));
m->handler.pfdcount--;
m->handler.pfds[m->handler.pfdcount].fd = 0;
m->handler.pfds[m->handler.pfdcount].events = 0;
/*
* Intentionally keeping i the same
* We need to look at it again
*/
}
}

m->last_read++;
}

Expand Down

0 comments on commit 89f974a

Please sign in to comment.