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: os.dup() creates an inheritable fd when handling a character file on Windows
Type: behavior Stage: resolved
Components: Extension Modules, Windows Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, josh.r, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords: patch

Created on 2019-06-13 10:12 by ZackerySpytz, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14051 merged ZackerySpytz, 2019-06-13 10:19
PR 14140 merged miss-islington, 2019-06-17 07:17
PR 14141 merged miss-islington, 2019-06-17 07:17
Messages (8)
msg345494 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2019-06-13 10:12
In PR 13739, Eryk Sun mentioned that the Windows implementation of os.dup() returns an inheritable fd when handling a character file. A comment in _Py_dup() makes it seem as though this is due to a belief that handles for character files cannot be made non-inheritable (which is wrong).
msg345513 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-13 12:44
If you care of inherited handles on Windows, please have a look at:

* https://github.com/python/cpython/pull/7827 from https://bugs.python.org/issue18174
* https://github.com/python/cpython/pull/7966 from https://bugs.python.org/issue33966

ref: https://pythondev.readthedocs.io/unstable_tests.html#windows-handles

I decided to give up because of multiprocessing race conditions. I failed to fix them.
msg345799 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-17 07:17
New changeset 28fca0c422b425a6be43be31add0a5328c16b0b8 by Victor Stinner (Zackery Spytz) in branch 'master':
bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows (GH-14051)
https://github.com/python/cpython/commit/28fca0c422b425a6be43be31add0a5328c16b0b8
msg345800 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-17 07:21
According to the discussion in PR 14051: if os.dup() fails to make the new file descriptor new inheritable for a character device, the error must not be ignored. Instead, the caller is supposed to use os.dup(fd, inheritable=False).

Before *this bugfix*, os.dup() didn't respect its contract: fd2 was inheritable sometimes. Now the caller is aware of such special case and so can handle it properly.
msg345824 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-17 08:45
New changeset 71589491ad0da27f57789b97354f6094a91e2eb3 by Victor Stinner (Miss Islington (bot)) in branch '3.7':
bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows (GH-14051) (GH-14141)
https://github.com/python/cpython/commit/71589491ad0da27f57789b97354f6094a91e2eb3
msg345825 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-17 08:45
New changeset 693945d45dfe50c843970cab3e3aa1fa3a3eddbe by Victor Stinner (Miss Islington (bot)) in branch '3.8':
bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows (GH-14051) (GH-14140)
https://github.com/python/cpython/commit/693945d45dfe50c843970cab3e3aa1fa3a3eddbe
msg345827 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-17 08:49
Thanks Zackery Spytz as usual!
msg347633 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2019-07-10 18:43
This may have caused a regression, see #37549.
History
Date User Action Args
2022-04-11 14:59:16adminsetgithub: 81448
2019-07-10 18:43:06josh.rsetnosy: + josh.r
messages: + msg347633
2019-06-17 08:49:27vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg345827

stage: patch review -> resolved
2019-06-17 08:45:29vstinnersetmessages: + msg345825
2019-06-17 08:45:07vstinnersetmessages: + msg345824
2019-06-17 07:21:01vstinnersetmessages: + msg345800
2019-06-17 07:17:44miss-islingtonsetpull_requests: + pull_request13982
2019-06-17 07:17:38miss-islingtonsetpull_requests: + pull_request13981
2019-06-17 07:17:18vstinnersetmessages: + msg345799
2019-06-13 12:44:38vstinnersetnosy: + vstinner
messages: + msg345513
2019-06-13 10:19:15ZackerySpytzsetkeywords: + patch
stage: patch review
pull_requests: + pull_request13913
2019-06-13 10:12:30ZackerySpytzcreate