• Benjamin Peterson's avatar
    bpo-31530: fix crash when multiple threads iterate over a file, round 2 (#5060) · dbf52e02
    Benjamin Peterson authored
    Multiple threads iterating over a file can corrupt the file's internal readahead
    buffer resulting in crashes. To fix this, cache buffer state thread-locally for
    the duration of a file_iternext call and only update the file's internal state
    after reading completes.
    
    No attempt is made to define or provide "reasonable" semantics for iterating
    over a file on multiple threads. (Non-crashing) races are still
    present. Duplicated, corrupt, and missing data will happen.
    
    This was originally fixed by 6401e567, which
    raised an exception from seek() and next() when concurrent operations were
    detected. Alas, this simpler solution breaks legitimate use cases such as
    capturing the standard streams when multiple threads are logging.
    dbf52e02
test_file2k.py 32.9 KB