From fd2abf98048a0062ee35ebe89605cf67a0d3b76d Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Fri, 7 Jul 2023 22:04:33 +0200 Subject: [PATCH] Handle EEXIST in async --- src/async.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/async.c b/src/async.c index ad73a56..61ca1ed 100644 --- a/src/async.c +++ b/src/async.c @@ -243,7 +243,12 @@ void async_thread(void) { ev.events = async_a2e(evt->events); ev.data.ptr = evt; - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, evt->fd, &ev) == -1) { + while (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, evt->fd, &ev) == -1) { + if (errno == EEXIST) { + errno = 0; + if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, evt->fd, NULL) != -1) + continue; + } critical("Unable to add file descriptor to epoll instance"); return; }