New GitHub issue #118981 from albertz:<br>

<hr>

<pre>
# Bug report

### Bug description:

https://github.com/python/cpython/blob/a705c1e44984afda2f7fb6d0816345d0843a6635/Lib/multiprocessing/popen_spawn_posix.py#L51-L72

What happens here:
* Two pipes get opened.
* The child proc gets spawned, the child fds are passed to it.
* It is written into the parent fd.
* The child fds are closed.

This order is wrong and can lead to hangs when the child proc crashes in between for whatever reason. Specifically, when the client crashes, then the parent will hang while trying to write into the parent fd, in this line:
https://github.com/python/cpython/blob/a705c1e44984afda2f7fb6d0816345d0843a6635/Lib/multiprocessing/popen_spawn_posix.py#L62

(I have this case because of some unpickling error happening in the child, but that's not really the point of the issue here.)

The fix should be easy: Move the code for closing the child fds up, right after the spawn. This is also the standard pattern for this kind of code.

Also reported here: https://github.com/rwth-i6/returnn/issues/1514


### CPython versions tested on:

CPython main branch

### Operating systems tested on:

Linux, Other
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/118981">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>