From d6e87aeba5654117a4799af2c63837941992b6b5 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 26 Feb 2026 23:18:55 +0100 Subject: [PATCH] eventloop_select: introduce error variable abort process if too many select errors. Prevents error logs from filling log partition. after 90 select errors the log level will be increased for the next calls. after 100 select errors the process aborts (will be restarted by systemd). TODO: inspect sockets to find the bad one. --- aqhome/events2/eventloop_select.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/aqhome/events2/eventloop_select.c b/aqhome/events2/eventloop_select.c index dd32b56..346314b 100644 --- a/aqhome/events2/eventloop_select.c +++ b/aqhome/events2/eventloop_select.c @@ -41,6 +41,7 @@ static void _signalReadyFdObjects(AQH_OBJECT_LIST2 *ol); void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop, int timeoutInMillisecs) { + static int selectErrorCount=0; fd_set fdRead; fd_set fdWrite; int highestFd=-1; @@ -61,6 +62,8 @@ void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop, int timeoutInMillisecs) rv=select(highestFd+1, &fdRead, &fdWrite, NULL, &tv); if (rv>0) { /* some fds became active */ + if (selectErrorCount) + selectErrorCount--; _markReadyFdObjects(eventLoop->fdObjectList, &fdRead, AQH_FDOBJECT_FDMODE_READ); _markReadyFdObjects(eventLoop->fdObjectList, &fdWrite, AQH_FDOBJECT_FDMODE_WRITE); _signalReadyFdObjects(eventLoop->fdObjectList); @@ -68,11 +71,24 @@ void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop, int timeoutInMillisecs) else if (rv<0) { if (errno!=EINTR) { /* error */ - DBG_ERROR(AQH_LOGDOMAIN, "Error on SELECT: %d (%s)", errno, strerror(errno)); + DBG_ERROR(AQH_LOGDOMAIN, "Error on SELECT: %d (%s)", errno, strerror(errno)); + selectErrorCount++; + /* TODO: walk through all sockets to find the bad one */ + if (selectErrorCount==90) { + /* increase log level */ + DBG_ERROR(AQH_LOGDOMAIN, "Increasing log level to INFO"); + GWEN_Logger_SetLevel(AQH_LOGDOMAIN, GWEN_LoggerLevel_Info); + } + else if (selectErrorCount==100) { + DBG_ERROR(AQH_LOGDOMAIN, "Aborting due to too many SELECT errors, will be restarted by systemd"); + abort(); + } } } else { /* no fd became active (TODO: maybe signal deep idle objects?) */ + if (selectErrorCount) + selectErrorCount--; } } }