Repository navigation
Description
When writing a compressed block to the underlying file fails, for example, with ENOSPC on a full disk, a writer from gzip_ng_threaded.open() blocks forever and never raises the error. By default, xopen 2.1.0 writes gzip files with gzip_ng_threaded at compression levels other than 1 and 2, and at every level when python-isal isn't installed. The igzip_threaded module in python-isal has the same bug: pycompression/python-isal#274 reports it, and pycompression/python-isal#275 fixes it.
The following script reproduces the bug on Linux with zlib-ng 1.0.0 from PyPI and CPython 3.14.8:
import os
from zlib_ng import gzip_ng_threaded
with gzip_ng_threaded.open("/dev/full", "wb") as f:
f.write(os.urandom(500_000))The script prints OSError: [Errno 28] No space left on device in a traceback from the _compress_and_write() thread and then never exits. With threads=3 added to the open() call, the traceback comes from the _write() thread instead, and the script still never exits. I didn't test free-threaded CPython.
In zlib-ng 1.0.0 and on the develop branch at 10d2ffd, the gzip_ng_threaded.py file calls self.raw.write(compressed) outside any try block in two places: line 391 in the _write() method, which runs when threads > 1, and line 416 in the _compress_and_write() method, which runs when threads == 1. When that call raises an exception, the thread exits without calling task_done() and without setting self.exception. Then _ThreadedGzipWriter.flush() blocks forever in one of its join() calls. Closing the object that open() returns blocks too: its close() method calls its flush() method, which calls _ThreadedGzipWriter.flush(). write() also blocks forever when the input queue for its next block is full.
The python-isal fix keeps the thread alive after a write error. The thread stores the error and discards later blocks until stop() puts a None sentinel on the queues. The writer's flush() and close() methods then raise the stored error. The fix doesn't apply directly to gzip_ng_threaded, which lacks two parts of python-isal's _ThreadedGzipWriter class: the None sentinels that stop() puts on the queues (pycompression/python-isal#270), and the flush() call at the start of _ThreadedGzipWriter.close() (pycompression/python-isal@5ef868b). I can port the fix after you review the python-isal pull request.
Activity
rhpvorderman commentedon Oct 20, 2026
Wow thanks. Yes, if you would do that I would be most grateful. These repositories are mostly mirrors except for the fact that the zlib modules are somewhat different due to ISA-L and zlib-ng implementation differences.