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.

Author eryksun
Recipients eryksun, gregory.p.smith, izbyshev, vstinner
Date 2020-12-28.14:11:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1609164719.71.0.275967226765.issue42738@roundup.psfhosted.org>
In-reply-to
Content
> Python 3.7 added the support for the PROC_THREAD_ATTRIBUTE_HANDLE_LIST 
> in subprocess.STARTUPINFO: lpAttributeList['handle_list'] parameter.

The motivating reason to add support for the WinAPI handle list was to allow changing the default to close_fds=True regardless of the need to inherit standard handles. However, even when using the handle list, one still has to make each handle in the list inheritable. Thus concurrent calls to os.system() and os.spawn*() -- which are not implemented via subprocess.Popen(), but should be -- may leak the handles in the list. If the default is changed to close_fds=False, then by default concurrent Popen() calls may also leak temporarily inheritable handles when a handle list isn't used to constrain inheritance.

Background

Windows implicitly duplicates standard I/O handles from a parent process to a child process if they're both console applications and the child inherits the console session. However, subprocess.Popen() requires standard I/O inheritance to work consistently even without an inherited console session. It explicitly inherits standard handles in the STARTUPINFO record, which requires CreateProcessW to be called with bInheritHandles as TRUE. In 3.7+, Popen() also passes the standard-handle values in a PROC_THREAD_ATTRIBUTE_HANDLE_LIST attribute that constrains inheritance, but handles in the list still have to be made inheritable before calling CreateProcessW. Thus they may be leaked by concurrent CreateProcessW calls that inherit handles without a constraining handle list.
History
Date User Action Args
2020-12-28 14:11:59eryksunsetrecipients: + eryksun, gregory.p.smith, vstinner, izbyshev
2020-12-28 14:11:59eryksunsetmessageid: <1609164719.71.0.275967226765.issue42738@roundup.psfhosted.org>
2020-12-28 14:11:59eryksunlinkissue42738 messages
2020-12-28 14:11:59eryksuncreate