Readit News logoReadit News
htfy96 · 8 months ago
Meanwhile VSCode's terminal still leaks Electron fds: https://github.com/microsoft/node-pty/issues/657

I get this proposal's rationale, but it seems that it would implicitly make fd leaks more prone in python programs

oseityphelysiol · 8 months ago
Of all the quirks with process spawning in posix keeping file descriptors open is the most problematic one I encountered. This bit into my ass while implementing a C library to have proper process spawning and stdio handling in LUA. I really wish file descriptors were non inheritable by default.
teddyh · 8 months ago
> I really wish file descriptors were non inheritable by default.

In Python 3.4, they are (released ten years ago).

int_19h · 8 months ago
But in POSIX, they are not, so any module implemented in C is still potentially problematic.
teddyh · 8 months ago
The counter-arguments presented seem persuasive. This was originally submitted in 2020, and closed in 2022. Why is it relevant or interesting today?

Deleted Comment

williamjackson · 8 months ago
loeg · 8 months ago
(The comments before 2022 are all the same; the newest comment is only on Github.)
nasretdinov · 8 months ago
Go goes slightly further and opens all descriptors with O_CLOEXEC by default, so if you ever execute an external command you have to go out of your way to preserve any descriptors, which is really nice in my opinion
loeg · 8 months ago
Python has done the same thing for the past 10 years for fds created by the runtime (Python 3.4). But 3rd party extensions / modules may create non-CLOEXEC fds.
mmastrac · 8 months ago
FDs really should have been opt-in for inheritability from the start, with the possible exception of stdio. Inheritability being an fcntl is definitely one of the worst bits -- if the APIs for fork()/etc were designed today it would probably take a list of FDs that would be dup2'd in the new child process.
stefan_ · 8 months ago
FDs optin, memory too given the insane performance pitfalls architectural issues and pernicious security problems (think cloning a CSPRNGs internal state) and suddenly you realize CreateProcessA was and always has been the superior API.
adzm · 8 months ago
> suddenly you realize CreateProcessA was and always has been the superior API

Throw in IOCP and you realize that NT is a pretty solid, well-thought-out OS

loeg · 8 months ago
> FDs really should have been opt-in for inheritability from the start, with the possible exception of stdio.

Yes.

> Inheritability being an fcntl is definitely one of the worst bits

Well, or you can use O_CLOEXEC in most APIs that create an fd.

mmastrac · 8 months ago
Yep, totally, although there are still some holes in that. pipe2 being missing on Darwin is one example. You also need to hope that all the libraries you're integrating with are using O_CLOEXEC as well.
glandium · 8 months ago
Even posix_spawn didn't fix this problem. https://pubs.opengroup.org/onlinepubs/007904975/functions/po...
loeg · 8 months ago
(2020), or perhaps 2021.
Pesthuf · 8 months ago
> On macOS, posix_spawn() is even a syscall.

First time I hear about this, interesting. I wonder what the performance benefits are like.