I am using the CBOR encoder and once saw the following error reported in exception dump
File: "/usr/local/lib/python3.7/dist-packages/persistqueue/serializers/cbor2.py", line 64, in load
length = length_struct.unpack(fp.read(4))[0]
struct.error: unpack requires a buffer of 4 bytes
Seems to be when reading the 4 bytes (32-bit integer) length, but presumably the read fails for some reason (none or not enough bytes to read).
I don't believe this should be possible (not unless something else has deleted the file).
The same code logic exists for other codecs (e.g. msgpack).
Should there be some safe guard exception handling when reading the length and also the data?
NOTE: this occurred when calling my clear() method from a sub-class. See #237
from persistqueue import (
Queue as PersistQueue,
Empty as PersistQueueEmpty,
Full as PersistQueueFull,
)
class MyPersistQueue(PersistQueue):
"""
Customised persistqueue.Queue
"""
def clear(self) -> None:
"""
Clear all items from queue.
persistqueue.Queue does not have a native `clear()` method.
"""
while True:
try:
self.get_nowait()
except PersistQueueEmpty:
break
I am using the CBOR encoder and once saw the following error reported in exception dump
Seems to be when reading the 4 bytes (32-bit integer) length, but presumably the read fails for some reason (none or not enough bytes to read).
I don't believe this should be possible (not unless something else has deleted the file).
The same code logic exists for other codecs (e.g.
msgpack).Should there be some safe guard exception handling when reading the length and also the data?
NOTE: this occurred when calling my
clear()method from a sub-class. See #237