This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6f735b1a86bc9fd302aa52c7eef947060910981b Author: Bowen Wang <[email protected]> AuthorDate: Fri Sep 4 15:22:45 2026 +0800 fs/epoll: fix ET starvation and lost ET events 1. epoll_teardown() never cleared notified in the ET branch when revents == 0. A POLLALWAYS notification carrying no pending event left the flag set for good: the node was scanned on every epoll_wait(), never reported and never registered again. 2. epoll_teardown() dropped ET events when the array was full. An ET node keeps its registration, so the driver does not notify again and the next epoll_wait() blocked on eph->sem with an event pending. Post the semaphore instead. Signed-off-by: Bowen Wang <[email protected]> --- fs/vfs/fs_epoll.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/fs/vfs/fs_epoll.c b/fs/vfs/fs_epoll.c index b44916729b9..2b234248177 100644 --- a/fs/vfs/fs_epoll.c +++ b/fs/vfs/fs_epoll.c @@ -506,6 +506,7 @@ static int epoll_teardown(FAR epoll_head_t *eph, FAR struct epoll_event *evs, { FAR epoll_node_t *tepn; FAR epoll_node_t *epn; + bool pending = false; int i = 0; int ret; @@ -532,7 +533,16 @@ static int epoll_teardown(FAR epoll_head_t *eph, FAR struct epoll_event *evs, if ((epn->pfd.events & EPOLLET) != 0) { - if (epn->pfd.revents != 0 && i < maxevents) + if (epn->pfd.revents == 0) + { + /* A POLLALWAYS notification with nothing to report. The + * registration is still valid; leaving the flag set would + * strand this node, never reported nor registered again. + */ + + epn->notified = false; + } + else if (i < maxevents) { evs[i].data = epn->data; evs[i++].events = epn->pfd.revents; @@ -545,6 +555,15 @@ static int epoll_teardown(FAR epoll_head_t *eph, FAR struct epoll_event *evs, list_add_tail(&eph->oneshot, &epn->node); } } + else + { + /* Array full. An ET node stays registered, so the driver + * will not notify again; post the semaphore below or the + * next epoll_wait() blocks with this event pending. + */ + + pending = true; + } } else { @@ -576,6 +595,18 @@ static int epoll_teardown(FAR epoll_head_t *eph, FAR struct epoll_event *evs, } nxrmutex_unlock(&eph->lock); + + if (pending) + { + int semcount = 0; + + nxsem_get_value(&eph->sem, &semcount); + if (semcount < 1) + { + nxsem_post(&eph->sem); + } + } + return i; }
