hiredis
hiredis copied to clipboard
File descriptor handlers leak on fork + exec
When fork
ing and exec
ing, file descriptors get leaked to the child process, which is not always ideal. One can always call fcntl
and set O_CLOEXEC
after establishing a connection, but this can lead to race conditions if a different thread is trying to fork
.
Apart from OS compatibility, are there any cases where one might want this sort of behaviour, meaning the sockets couldn't be created with SOCK_CLOEXEC
? If so, how could we implement some sort of flag or another Connect*
in order to accommodate for that?
I've been bitten by this at work and I went with calling fcntl
, but I'd like to have a more atomic fix, and I'm willing to contribute a patch to this, I'd just like to have some input on what sort of API/behaviour is best. :)