From 68b10060e568cf12d378849de8ceb03563e2281c Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Fri, 16 Dec 2016 11:30:33 +0100 Subject: [PATCH] tcpsrv: Sleeptimer added when accept loops because of no free file handles. When file handle limit is reached, tcpsrv cannot accept new sockets and will start looping until it can. The 20ms sleep avoids high cpu usage. --- runtime/tcpsrv.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/runtime/tcpsrv.c b/runtime/tcpsrv.c index 9d001cc39..c7134eaa6 100644 --- a/runtime/tcpsrv.c +++ b/runtime/tcpsrv.c @@ -698,7 +698,7 @@ processWorkset(tcpsrv_t *pThis, nspoll_t *pPoll, int numEntries, nsd_epworkset_t ABORT_FINALIZE(RS_RET_FORCE_TERM); if(numEntries == 1) { /* process self, save context switch */ - processWorksetItem(pThis, pPoll, workset[numEntries-1].id, workset[numEntries-1].pUsr); + iRet = processWorksetItem(pThis, pPoll, workset[numEntries-1].id, workset[numEntries-1].pUsr); } else { pthread_mutex_lock(&wrkrMut); /* check if there is a free worker */ @@ -721,7 +721,7 @@ processWorkset(tcpsrv_t *pThis, nspoll_t *pPoll, int numEntries, nsd_epworkset_t } else { pthread_mutex_unlock(&wrkrMut); /* no free worker, so we process this one ourselfs */ - processWorksetItem(pThis, pPoll, workset[numEntries-1].id, + iRet = processWorksetItem(pThis, pPoll, workset[numEntries-1].id, workset[numEntries-1].pUsr); } } @@ -870,6 +870,7 @@ Run(tcpsrv_t *pThis) { DEFiRet; int i; + int bFailed = FALSE; /* If set to TRUE, accept failed already */ nsd_epworkset_t workset[128]; /* 128 is currently fixed num of concurrent requests */ int numEntries; nspoll_t *pPoll = NULL; @@ -928,7 +929,22 @@ Run(tcpsrv_t *pThis) if(localRet != RS_RET_OK) continue; - processWorkset(pThis, pPoll, numEntries, workset); + localRet = processWorkset(pThis, pPoll, numEntries, workset); + if(localRet != RS_RET_OK) { + if (bFailed == FALSE) { + errmsg.LogError(0, localRet, "tcpsrv listener (inputname: '%s') failed to processed incoming connection with error %d", + (pThis->pszInputName == NULL) ? (uchar*)"*UNSET*" : pThis->pszInputName, localRet); + bFailed = TRUE; + } else { + DBGPRINTF("tcpsrv listener (inputname: '%s') still failing to process incoming connection with error %d\n", + (pThis->pszInputName == NULL) ? (uchar*)"*UNSET*" : pThis->pszInputName, localRet); + } + /* Sleep 20ms */ + srSleep(0,20000); + } else { + /* Reset bFailed State */ + bFailed = FALSE; + } } /* remove the tcp listen sockets from the epoll set */