From 00f53c1aac85b7d0b7ef241656d3b47618eaea9b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 1 May 2025 10:27:50 +1000 Subject: [PATCH] fix(ei): Drain all events sitting in our pipe If we're starved for resources, we may end up with more than 64 notifications in our pipe before we get to actually read them. Those notifications are just that though, so let's drain them. --- src/lib/platform/EiEventQueueBuffer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/platform/EiEventQueueBuffer.cpp b/src/lib/platform/EiEventQueueBuffer.cpp index 1143a3674..ae92c4b9b 100644 --- a/src/lib/platform/EiEventQueueBuffer.cpp +++ b/src/lib/platform/EiEventQueueBuffer.cpp @@ -81,8 +81,12 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms) // and potentially testCancel if (pfds[PIPEFD].revents & POLLIN) { char buf[64]; - auto result = read(pipe_r_, buf, sizeof(buf)); // discard - LOG_DEBUG2("event queue read result: %d", result); + ssize_t total = 0; + ssize_t result; + while ((result = read(pipe_r_, buf, sizeof(buf)) > 0)) { + total += result; + } + LOG_DEBUG2("event queue read result: %d (total drained: %zd)", result, total); } } Thread::testCancel();