adding guard for polling loop to prevent CPU exhastion in the case of system misbihavior

This commit is contained in:
z3APA3A committed 2020-10-14 18:58:52 +03:00
1 parent 47affa0add
commit 637cb2e76d
3 files changed
+27 -14

No files matched your search

+18 -5
View File
@@ -57,6 +57,7 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
FILTER_ACTION action;
int res;
SASIZETYPE sasize;
int needaction = 0;
#ifdef WITHSPLICE
uint64_t inclientpipe = 0, inserverpipe = 0;
@@ -155,8 +156,11 @@ sprintf(logbuf, "int FROMCLIENT = %d, TOCLIENTBUF = %d, FROMCLIENTBUF = %d, TOSE
log(logbuf);
#endif
if(needaction > 2 && !sleeptime){
sleeptime = (1<<(needaction-2));
}
if(sleeptime > 0) {
if(sleeptime > (timeo * 1000)){RETURN (92);}
if(sleeptime > (timeo * 1000)){RETURN (93);}
memset(fds, 0, sizeof(fds));
fds[0].fd = param->clisock;
fds[1].fd = param->remsock;
@@ -216,6 +220,7 @@ log("done send to server from buf");
sl1 = (*param->bandlimfunc)(param, 0, res);
if(sl1 > sleeptime) sleeptime = sl1;
}
needaction = 0;
continue;
}
}
@@ -247,6 +252,7 @@ log("done send to client from buf");
param->srvoffset += res;
if(param->srvoffset == param->srvinbuf)param->srvoffset = param->srvinbuf =0;
if(param->srvinbuf < param->srvbufsize) TOSERVERBUF = 1;
needaction = 0;
continue;
}
}
@@ -270,6 +276,7 @@ log("done send to server from pipe");
sl1 = (*param->bandlimfunc)(param, 0, res);
if(sl1 > sleeptime) sleeptime = sl1;
}
needaction = 0;
continue;
}
else {
@@ -288,6 +295,7 @@ log("done send to client from pipe");
inserverpipe -= res;
fromserver -= res;
if(fromserver)TOSERVERPIPE = 1;
needaction = 0;
continue;
}
else {
@@ -313,6 +321,7 @@ log("done read from client to pipe");
#endif
inclientpipe += res;
if(inclientpipe >= MAXSPLICE) TOCLIENTPIPE = 0;
needaction = 0;
continue;
}
}
@@ -346,8 +355,9 @@ log("done read from server to pipe\n");
fromserver = inserverpipe;
FROMSERVER = 0;
}
needaction = 0;
continue;
}
continue;
}
}
else
@@ -370,6 +380,7 @@ log("done read from client to buf");
inclientbuf += res;
param->cliinbuf += res;
if(param->clibufsize == param->cliinbuf) TOCLIENTBUF = 0;
needaction = 0;
continue;
}
}
@@ -402,6 +413,7 @@ log("done read from server to buf");
fromserver = inserverbuf;
FROMSERVER = 0;
}
needaction = 0;
continue;
}
}
@@ -639,7 +651,7 @@ log("leaving poll");
#ifdef WITHLOG
log("poll error");
#endif
if(errno != EAGAIN && errno != EINTR) RETURN(91);
if(errno != EINTR) RETURN(91);
break;
}
if(res < 1){
@@ -650,14 +662,15 @@ log("timeout");
}
}
}
needaction++;
}
res = 0;
if(!fromserver && param->waitserver64) res = 98;
else if(!fromclient && param->waitclient64) res = 99;
else if((inclientbuf || inserverbuf)) res = HASERROR?93:94;
else if((inclientbuf || inserverbuf)) res = 94;
#ifdef WITHSPLICE
else if(inclientpipe || inserverpipe) res = HASERROR?93:94;
else if(inclientpipe || inserverpipe) res = 94;
#endif
else if(HASERROR) res = 94+HASERROR;