TcpSocket try_clone() sets close-on-exec but this isn't documented

e03f59f
Opened by Seth Arnold at 2024-12-07 05:41:11

Hello, the TcpSocket try_clone() method calls into .duplicate(), which sets the close-on-exec flag on the socket:

https://doc.rust-lang.org/src/std/net/tcp.rs.html#255-257 https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/fd.rs#L197

I believe the documentation for try_clone() should be extended to describe:

  • That this is an operation with the underlying operating system, dup() or WSADuplicateSocket() or whatever is appropriate (this would help address very similar issue 45536)
  • That the duplication operation also sets the close-on-exec flag.

Thanks

  1. Hello, the TcpSocket try_clone() method calls into .duplicate(), which sets the close-on-exec flag on the socket:

    https://doc.rust-lang.org/src/std/net/tcp.rs.html#255-257 https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/fd.rs#L197

    I believe the documentation for try_clone() should be extended to describe:

    • That this is an operation with the underlying operating system, dup() or WSADuplicateSocket() or whatever is appropriate ~~(this would help address very similar issue 45536)~~
    • That the duplication operation also sets the close-on-exec flag.

    Thanks

    <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_ASSIGN_START --> <!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"HypheX"}$$TRIAGEBOT_ASSIGN_DATA_END --> <!-- TRIAGEBOT_ASSIGN_END --> <!-- TRIAGEBOT_END -->

    Dylan DPC at 2024-05-14 05:18:23

  2. @rust-lang/libs checking with y'all before a PR gets opened for this – is it okay to specify that close-on-exec flag (CLOEXEC) gets set as a platform-specific behavior for TcpStream::try_clone?

    Corey Farwell at 2018-02-11 18:00:36

  3. @frewsxcv ah yeah every file descriptor libstd creates has CLOEXEC, so this should be good to document

    Alex Crichton at 2018-02-11 18:45:12

  4. so next step here is deciding how to document this. i imagine there are a bunch of APIs in the standard library that create file descriptors. would it be excessive to add a # Platform-specific behavior to each of these APIs mentioning which platforms set CLOEXEC?

    Corey Farwell at 2018-03-27 12:54:55

  5. @frewsxcv yup!

    Steve Klabnik at 2018-05-29 08:57:54

  6. @rustbot claim

    Lisa FS at 2024-12-07 05:41:11