-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Disable socket inheritance on Windows and macOS #32903
Conversation
f56ce9f
to
2f2e409
Compare
We already disabled it on Linux. Doing the same for Windows and macOS.
2f2e409
to
35e25da
Compare
@CIPop - any feedback on this Sockets change? |
Agreed, it would be super rare. You could add a test for this similar to this one: aspnet/KestrelHttpServer#2944. On Linux we use the accept4 call to set CLOEXEC for accepted connections. I don't know how this is on Mac/Windows. Maybe this is copied from the listen socket, or maybe you need to also change the call/flags. |
Ah, right, I'll take care of those.
Of course. Thanks. |
Windows is inheriting it from the listening socket, so nothing further was needed there beyond my initial changes. And we actually already handled the accept case with fcntl and CLOEXEC on systems without SOCK_CLOEXEC, so nothing further was needed there, either. So I've just augmented the PR with a test. |
Thanks for checking. The test LGTM. CI still has some issue with it:
|
f304452
to
5f4a716
Compare
Oops. The problem with a last minute tweak before git push. Fixed. |
* Disable socket inheritance on Windows and macOS We already disabled it on Linux. Doing the same for Windows and macOS. * Add test for socket non-inheritance * Disable new test on netfx Commit migrated from dotnet/corefx@6ccd555
We already disabled it on Linux. Doing the same for Windows and macOS.
@davidsh, @geoffkizer, @tmds, can you think of any real scenarios that'll break from doing this? We don't currently have a
Socket
ctor that takes a handle, so someone would need to be inheriting the handle, passing the handle IntPtr into the child process in some way (e.g. cmdline arg), and then using something likeFileStream
to read/write it as an arbitrary handle. You can do that, but it seems really rare.I wrote a test for this as well, but ended up deleting it, as it could easily have false positives, since the child process could easily have another handle with the same value as the one in the parent process, especially on Unix.
Fixes https://github.com/dotnet/corefx/issues/32902