[New-bugs-announce] [issue43142] Do not add duplicate FDs to list in duplicate_for_child()

Sanchit report at bugs.python.org
Sat Feb 6 00:50:31 EST 2021


New submission from Sanchit <sanchit at cs.wisc.edu>:

While spawning, if a process having code built on top of Python's multiprocessing module calls multiprocessing.reduction.DupFd() (in /Lib/multiprocessing/reduction.py) multiple times on the same File descriptor by mistake, then it ends up invoking duplicate_for_child(fd)) of the class Popen, which, in turn, adds a duplicate FD to a list.
This list is then used in spawnv_passfds() in /Lib/multiprocessing/util.py, which uses that list as an argument in a call of _posixsubprocess.fork_exec().

In Modules/_posixsubprocess.c, checks exist to ensure that all the FDs in the list are unique, positive, and in a sorted order.
If duplicate entries are found, a ValueError: bad value(s) in fds_to_keep exception is raised, and the execution is terminated.
Even if this exception were somehow handled, a developer can't change the aforementioned FD list in Python without breaking modularity.

It's better to let developers get away with calling multiprocessing.reduction.DupFd() (in /Lib/multiprocessing/reduction.py) on by not accepting duplicate entries in the first place, so that spawning a process can be successful.

----------
components: Library (Lib)
messages: 386546
nosy: sanchit
priority: normal
severity: normal
status: open
title: Do not add duplicate FDs to list in duplicate_for_child()
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43142>
_______________________________________


More information about the New-bugs-announce mailing list