This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Do not add duplicate FDs to list in duplicate_for_child()
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: davin, pitrou, sanchit, terry.reedy
Priority: normal Keywords: patch

Created on 2021-02-06 05:50 by sanchit, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 24461 open sanchit, 2021-02-06 05:54
Messages (4)
msg386546 - (view) Author: Sanchit (sanchit) * Date: 2021-02-06 05:50
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.
msg386881 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-02-12 21:43
3.7 and before only get security fixes.
msg386897 - (view) Author: Sanchit (sanchit) * Date: 2021-02-13 01:52
But can you please add this fix in versions 3.8 & beyond?
Thanks!
________________________________
From: report=bugs.python.org@roundup.psfhosted.org <report=bugs.python.org@roundup.psfhosted.org> on behalf of Terry J. Reedy <report@bugs.python.org>
Sent: Friday, February 12, 2021 3:43 PM
To: SANCHIT JAIN <sanchit@cs.wisc.edu>
Subject: [issue43142] Do not add duplicate FDs to list in duplicate_for_child()

Terry J. Reedy <tjreedy@udel.edu> added the comment:

3.7 and before only get security fixes.

----------
nosy: +davin, pitrou, terry.reedy
versions:  -Python 3.6, Python 3.7

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue43142>
_______________________________________
msg386913 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-02-13 05:57
I can't (lacking multiprocessing knowledge), but someone else might.

PS: when replying via email, please delete post you are responding to.  When added to the web page, the copy is redundant noise.
History
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87308
2021-02-13 05:57:18terry.reedysetmessages: + msg386913
2021-02-13 01:52:04sanchitsetmessages: + msg386897
2021-02-12 21:43:22terry.reedysetnosy: + terry.reedy, pitrou, davin

messages: + msg386881
versions: - Python 3.6, Python 3.7
2021-02-06 05:54:24sanchitsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23257
2021-02-06 05:50:31sanchitcreate