Skip to content

File descriptor handlers leak on fork + exec #555

@feliperuiz

Description

@feliperuiz

When forking and execing, 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. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions