Oops when player thread keeps reading input unsuccessfully
Reading input fails after EOF and while the current command is
aborted. Commands should detect that and fail. If a command neglects
to do that in a loop, the loop can become infinite. This is
especially bad after EOF, because then the client might not read
output anymore. Output gets buffered until memory runs out.
Mitigate such bugs by counting how many calls have failed in a row,
oopsing on the 256th, and sleeping one minute from the 256th on.
(cherry picked from commit 49c24d7b78
)
This commit is contained in:
parent
6aefeea2a1
commit
18ae6c5f78
2 changed files with 14 additions and 4 deletions
|
@ -78,6 +78,7 @@ struct player {
|
||||||
time_t curup; /* when last input was received */
|
time_t curup; /* when last input was received */
|
||||||
int aborted; /* interrupt cookie received? */
|
int aborted; /* interrupt cookie received? */
|
||||||
int eof; /* EOF (cookie or real) received? */
|
int eof; /* EOF (cookie or real) received? */
|
||||||
|
int recvfail; /* #recvclient() failures */
|
||||||
int curid; /* for pr, cur. line's id, -1 none */
|
int curid; /* for pr, cur. line's id, -1 none */
|
||||||
char *map; /* pointer to in-mem map */
|
char *map; /* pointer to in-mem map */
|
||||||
char *bmap; /* pointer to in-mem bmap */
|
char *bmap; /* pointer to in-mem bmap */
|
||||||
|
|
|
@ -90,10 +90,19 @@ recvclient(char *cmd, int size)
|
||||||
player->eof = 1;
|
player->eof = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->eof)
|
if (player->aborted || player->eof) {
|
||||||
return -1;
|
player->recvfail++;
|
||||||
if (player->aborted)
|
if (player->recvfail > 255) {
|
||||||
return -2;
|
/*
|
||||||
|
* Looks like the thread is stuck in a loop that fails to
|
||||||
|
* check errors; oops once, then slow it down drastically.
|
||||||
|
*/
|
||||||
|
CANT_HAPPEN(player->recvfail == 256);
|
||||||
|
empth_sleep(time(NULL) + 60);
|
||||||
|
}
|
||||||
|
return player->eof ? -1 : -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
player->recvfail = 0;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue