From b778b712fc307b5f32adf53eafb27833b9902397 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 5 Dec 2018 07:04:58 -0500 Subject: [PATCH] fix poller race condition One thread may close an fd while another thread is processing the result events that can include a POLLOUT for the same fd. That same fd might then get re-opened as another type of object and get added to the poller again. When the POLLOUT event then gets processed, no `writeable` function would be present. This is not a clean fix for the underlying race condition as stray events might still get processed, but seeing extra stray events should not be a problem. Change-Id: I2fa2277bb0ddf512f53917297bd4220fe794dd0e --- daemon/poller.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/daemon/poller.c b/daemon/poller.c index ccdbf7a9f..7a5455923 100644 --- a/daemon/poller.c +++ b/daemon/poller.c @@ -344,7 +344,9 @@ int poller_poll(struct poller *p, int timeout) { abort(); mutex_unlock(&p->lock); - it->item.writeable(it->item.fd, it->item.obj, it->item.uintp); + + if (it->item.writeable) + it->item.writeable(it->item.fd, it->item.obj, it->item.uintp); } else if ((ev->events & POLLIN)) it->item.readable(it->item.fd, it->item.obj, it->item.uintp);