Skip to content

Fix BlobIO cleanup deadlock - #1491

Open
Werkov wants to merge 2 commits into
libgit2:masterfrom
Werkov:fix-1488
Open

Fix BlobIO cleanup deadlock#1491
Werkov wants to merge 2 commits into
libgit2:masterfrom
Werkov:fix-1488

Conversation

@Werkov

@Werkov Werkov commented Sep 10, 2026

Copy link
Copy Markdown

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 the chunk_size is not runtime-changeable from tests).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant