From 85f31afee81a08f54b7c032201159d6d4850edcf Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Sat, 14 Dec 2024 18:42:56 +0800 Subject: [PATCH 1/2] Check node 'removed' flag before next read. --- src/kernel/poller.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/kernel/poller.c b/src/kernel/poller.c index e4eaf0ab49..15065ed878 100644 --- a/src/kernel/poller.c +++ b/src/kernel/poller.c @@ -465,6 +465,9 @@ static void __poller_handle_read(struct __poller_node *node, if (nleft < 0) break; + + if (node->removed) + return; } if (__poller_remove_node(node, poller)) @@ -614,6 +617,9 @@ static void __poller_handle_listen(struct __poller_node *node, node->res = res; if (!res) break; + + if (node->removed) + return; } if (__poller_remove_node(node, poller)) @@ -689,6 +695,9 @@ static void __poller_handle_recvfrom(struct __poller_node *node, node->res = res; if (!res) break; + + if (node->removed) + return; } if (__poller_remove_node(node, poller)) @@ -828,6 +837,9 @@ static void __poller_handle_event(struct __poller_node *node, node->res = res; if (!res) break; + + if (node->removed) + return; } } @@ -869,6 +881,9 @@ static void __poller_handle_notify(struct __poller_node *node, node->res = res; if (!res) break; + + if (node->removed) + return; } else if (n < 0 && errno == EAGAIN) return; From 195848b27b7040151df96673543b2a1adc6ec4db Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Sat, 14 Dec 2024 19:29:24 +0800 Subject: [PATCH 2/2] Add __poller_close_pfd(). --- src/kernel/poller.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/kernel/poller.c b/src/kernel/poller.c index 15065ed878..60b9d3e785 100644 --- a/src/kernel/poller.c +++ b/src/kernel/poller.c @@ -90,6 +90,11 @@ static inline int __poller_create_pfd() return epoll_create(1); } +static inline int __poller_close_pfd(int fd) +{ + return close(fd); +} + static inline int __poller_add_fd(int fd, int event, void *data, poller_t *poller) { @@ -171,6 +176,11 @@ static inline int __poller_create_pfd() return kqueue(); } +static inline int __poller_close_pfd(int fd) +{ + return close(fd); +} + static inline int __poller_add_fd(int fd, int event, void *data, poller_t *poller) { @@ -1176,7 +1186,7 @@ poller_t *__poller_create(void **nodes_buf, const struct poller_params *params) __poller_close_timerfd(poller->timerfd); } - close(poller->pfd); + __poller_close_pfd(poller->pfd); } free(poller); @@ -1204,7 +1214,7 @@ void __poller_destroy(poller_t *poller) { pthread_mutex_destroy(&poller->mutex); __poller_close_timerfd(poller->timerfd); - close(poller->pfd); + __poller_close_pfd(poller->pfd); free(poller); }