]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-31530: fix crash when multiple threads iterate over a file, round 2 (#5060)
authorBenjamin Peterson <benjamin@python.org>
Tue, 2 Jan 2018 17:25:41 +0000 (09:25 -0800)
committerGitHub <noreply@github.com>
Tue, 2 Jan 2018 17:25:41 +0000 (09:25 -0800)
commitdbf52e02f18dac6f5f0a64f78932f3dc6efc056b
treed506cffda230dde7ccb2bf9c2ba4e40f749b18c3
parent0e0d1017a4c8ad6f77ee42d7b640463058037f62
bpo-31530: fix crash when multiple threads iterate over a file, round 2 (#5060)

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 6401e5671781eb217ee1afb4603cc0d1b0367ae6, 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.
Lib/test/test_file2k.py
Misc/NEWS.d/next/Core and Builtins/2017-09-20-18-28-09.bpo-31530.CdLOM7.rst
Objects/fileobject.c