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

Segfault when closing BufferedWriter from a different thread #76157

Closed
benfogle mannequin opened this issue Nov 8, 2017 · 3 comments
Closed

Segfault when closing BufferedWriter from a different thread #76157

benfogle mannequin opened this issue Nov 8, 2017 · 3 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@benfogle
Copy link
Mannequin

benfogle mannequin commented Nov 8, 2017

BPO 31976
Nosy @pitrou, @benjaminp, @vadmium, @benfogle
PRs
  • bpo-31976: Fix race condition when flushing a file is slow. #4331
  • 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 2017-11-10.21:05:15.294>
    created_at = <Date 2017-11-08.04:27:27.470>
    labels = ['interpreter-core', '3.7', 'type-crash']
    title = 'Segfault when closing BufferedWriter from a different thread'
    updated_at = <Date 2017-11-10.21:05:15.294>
    user = 'https://github.com/benfogle'

    bugs.python.org fields:

    activity = <Date 2017-11-10.21:05:15.294>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-11-10.21:05:15.294>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2017-11-08.04:27:27.470>
    creator = 'benfogle'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31976
    keywords = ['patch']
    message_count = 3.0
    messages = ['305803', '306048', '306049']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'benjamin.peterson', 'stutzbach', 'martin.panter', 'benfogle']
    pr_nums = ['4331']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue31976'
    versions = ['Python 3.7']

    @benfogle
    Copy link
    Mannequin Author

    benfogle mannequin commented Nov 8, 2017

    To reproduce:

    import threading
    import io
    import time
    import _pyio
    
    class MyFileIO(io.FileIO):
        def flush(self):
            # Simulate a slow flush. Slow disk, etc.
            time.sleep(0.25)
            super().flush()
    
    raw = MyFileIO('test.dat', 'wb')
    #fp = _pyio.BufferedWriter(raw)
    fp = io.BufferedWriter(raw)
    t1 = threading.Thread(target=fp.close)
    t1.start()
    time.sleep(0.1) # Ensure t1 is sleeping in fp.close()/raw.flush()
    fp.write(b'test')
    t1.join()
    

    _pyio.BufferedWriter ignores the error completely rather than throwing a ValueError("write to closed file").

    @benfogle benfogle mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Nov 8, 2017
    @pitrou
    Copy link
    Member

    pitrou commented Nov 10, 2017

    New changeset 9703f09 by Antoine Pitrou (benfogle) in branch 'master':
    bpo-31976: Fix race condition when flushing a file is slow. (bpo-4331)
    9703f09

    @pitrou
    Copy link
    Member

    pitrou commented Nov 10, 2017

    Thank you for posting this Benjamin. As I said on the PR, I don't think I want to backport this to 3.6, as it is always delicate to reason about subclassing and threads.

    @pitrou pitrou closed this as completed Nov 10, 2017
    @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 interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant