Fix BlobIO cleanup deadlock - #1491
Open
Werkov wants to merge 2 commits into
Open
Conversation
When reading less than 8 KiB from the blob's data (io.DEFAULT_BUFFER_SIZE), the close() method would hang. Namely, close() thread would wait for self._writer_closed but the writer thread that'd set this is blocked by waiting in Blob__write_to_queue/.../blob_filter_stream_write/queue.put. The queue remains "full" (maxsize=1) because of unread data and no progress happens. Fix this by switching to "busy" wait for _writer_closed thus we empty the queue from the main thread and writer thread can proceed to its termination. Fixes libgit2#1488 Assisted-by: sonnet-5
The reader won't properly synchronize threads and when a file larger than DEFAULT_CHUNK_SIZE (8 KiB) is partially read, the close() method would hand in deadlock. Note: test/test_blob.py::test_blob_partial_read will hang indefinitely without a fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an attempt at fixing #1488.
It adds a busy wait in the BlobIO cleanup path, it stands the tests and fixes the reported deadlock. (This idea comes from LLM.)
It also adds a testcase with two caveats: there's new binary data in repo (bigrepo.zip) and the test before the fix hangs the whole pytest suite hence it's meant to be run either in isolation (
test/test_blob.py::test_blob_partial_read) or with the fix. I found no pre-existing test/data repo with large enough file (and thechunk_sizeis not runtime-changeable from tests).