Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ?cloexec parameter to Lwt_unix functions that create file descriptors #327

Closed
mfp opened this issue Mar 26, 2017 · 1 comment · Fixed by #901
Closed

Add ?cloexec parameter to Lwt_unix functions that create file descriptors #327

mfp opened this issue Mar 26, 2017 · 1 comment · Fixed by #901
Milestone

Comments

@mfp
Copy link
Collaborator

mfp commented Mar 26, 2017

OCaml 4.05 adds an optional cloexec parameter to several Unix functions, allowing the close-on-exec flag to be set as the operation is performed atomically on some platforms (limited to Linux atm.) -- otherwise there's a race condition when there are multiple (system) threads.

These functions would be affected: Lwt_unix.dup, dup2, pipe, socket, socketpair, accept.
Other functions that build on them and could also take ?cloexec: accept_n, pipe_in, pipe_out.

@aantron
Copy link
Collaborator

aantron commented Aug 3, 2019

I'm closing this issue for now, because:

  • The issue with multiple threads is probably less likely in typical Lwt programs, than even in programs using only Unix.
  • We haven't had any reports of a problem due to this.

We can reopen and fix later, if necessary.

Here's a link to text about the issue in module Unix: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html#VALset_close_on_exec.

@aantron aantron closed this as completed Aug 3, 2019
MisterDA added a commit to MisterDA/lwt that referenced this issue Nov 9, 2021
In the Lwt_unix module, add `?cloexec:bool` optional arguments to
functions that create file descriptors (`dup`, `dup2`, `pipe`,
`pipe_in`, `pipe_out`, `socket`, `socketpair`, `accept`, `accept_n`).
The `?cloexec` argument is simply forwarded to the wrapped Unix
function (with OCaml >= 4.05, see [ocaml/ocaml#650][650]), or emulated
as best-effort with `Unix.set_close_on_exec` on older OCaml versions.

Fix ocsigen#327. Fix ocsigen#847. See also ocsigen#872.

[650]: ocaml/ocaml#650
smorimoto pushed a commit to raphael-proust/lwt that referenced this issue Dec 2, 2021
In the Lwt_unix module, add `?cloexec:bool` optional arguments to
functions that create file descriptors (`dup`, `dup2`, `pipe`,
`pipe_in`, `pipe_out`, `socket`, `socketpair`, `accept`, `accept_n`).
The `?cloexec` argument is simply forwarded to the wrapped Unix
function (with OCaml >= 4.05, see [ocaml/ocaml#650][650]), or emulated
as best-effort with `Unix.set_close_on_exec` on older OCaml versions.

Fix ocsigen#327. Fix ocsigen#847. See also ocsigen#872.

[650]: ocaml/ocaml#650
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants