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.
This commit is contained in:
Martin Preuss
2026-02-26 23:18:55 +01:00
parent 56f2cf6870
commit d6e87aeba5

View File

@@ -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);
@@ -69,10 +72,23 @@ void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop, int timeoutInMillisecs)
if (errno!=EINTR) {
/* error */
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--;
}
}
}