Open suyashmahar opened 4 years ago
I think it's to handle the following case:
while (1)
{
int fd = accept();
int pid = fork();
if (pid) { close(fd); wait(pid); }
else { handle_request(fd); }
}
If we desock the program, we probably want to only handle one request (at least, this has been my use-case so far), hence the exit on the second accept
.
I'm all for having that controlled by an environment variable, though!
That use case makes a lot of sense. However, I imagine a lot of people (myself included) are using this on servers that offload the request to a thread pool or use nonblocking I/O to accept a large number of concurrent connections. I'm using desock on nginx, and it exits before the first request can be serviced.
Should this be the default behavior? Wouldn't it be better to have an optional env var to enable this on applications that only service one request at a time?
My commit dd96c133f6651380e6204f01c70d36d51af7e73a which has been merged moves the exit
call from accept
to close
/shutdown
, so this should fix the issue.
When trying to use redis with desock I ran into an issue where redis would exit right after it receives any input in STDIN, using gdb I found out that this is due to the exit(0) call in
desock.c::accept()
. Now, when I comment out line 216 and 217 everything works as expected.I see that this was added with this commit, any reason why redis behaves this way?