Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.dup() creates an inheritable fd when handling a character file on Windows #81448

Closed
ZackerySpytz mannequin opened this issue Jun 13, 2019 · 8 comments
Closed

os.dup() creates an inheritable fd when handling a character file on Windows #81448

ZackerySpytz mannequin opened this issue Jun 13, 2019 · 8 comments
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes extension-modules C modules in the Modules dir OS-windows type-bug An unexpected behavior, bug, or error

Comments

@ZackerySpytz
Copy link
Mannequin

ZackerySpytz mannequin commented Jun 13, 2019

BPO 37267
Nosy @pfmoore, @vstinner, @tjguk, @zware, @zooba, @MojoVampire, @ZackerySpytz
PRs
  • bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows #14051
  • [3.8] bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows (GH-14051) #14140
  • [3.7] bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows (GH-14051) #14141
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-06-17.08:49:27.884>
    created_at = <Date 2019-06-13.10:12:30.664>
    labels = ['type-bug', '3.8', '3.9', 'extension-modules', '3.7', 'OS-windows']
    title = 'os.dup() creates an inheritable fd when handling a character file on Windows'
    updated_at = <Date 2019-07-10.18:43:06.815>
    user = 'https://github.com/ZackerySpytz'

    bugs.python.org fields:

    activity = <Date 2019-07-10.18:43:06.815>
    actor = 'josh.r'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-06-17.08:49:27.884>
    closer = 'vstinner'
    components = ['Extension Modules', 'Windows']
    creation = <Date 2019-06-13.10:12:30.664>
    creator = 'ZackerySpytz'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37267
    keywords = ['patch']
    message_count = 8.0
    messages = ['345494', '345513', '345799', '345800', '345824', '345825', '345827', '347633']
    nosy_count = 7.0
    nosy_names = ['paul.moore', 'vstinner', 'tim.golden', 'zach.ware', 'steve.dower', 'josh.r', 'ZackerySpytz']
    pr_nums = ['14051', '14140', '14141']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37267'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @ZackerySpytz
    Copy link
    Mannequin Author

    ZackerySpytz mannequin commented Jun 13, 2019

    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).

    @ZackerySpytz ZackerySpytz mannequin added 3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes extension-modules C modules in the Modules dir OS-windows type-bug An unexpected behavior, bug, or error labels Jun 13, 2019
    @vstinner
    Copy link
    Member

    If you care of inherited handles on Windows, please have a look at:

    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.

    @vstinner
    Copy link
    Member

    New changeset 28fca0c by Victor Stinner (Zackery Spytz) in branch 'master':
    bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows (GH-14051)
    28fca0c

    @vstinner
    Copy link
    Member

    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.

    @vstinner
    Copy link
    Member

    New changeset 7158949 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)
    7158949

    @vstinner
    Copy link
    Member

    New changeset 693945d 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)
    693945d

    @vstinner
    Copy link
    Member

    Thanks Zackery Spytz as usual!

    @MojoVampire
    Copy link
    Mannequin

    MojoVampire mannequin commented Jul 10, 2019

    This may have caused a regression, see bpo-37549.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 (EOL) end of life 3.9 only security fixes extension-modules C modules in the Modules dir OS-windows type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant