Description
Zarr version
3.0.8
Numcodecs version
0.15.1
Python Version
3.11.11
Operating System
Linux
Installation
uv pip with global python within Docker based on Image "pytorch/pytorch:2.6.0-cuda12.4-cudnn9-runtime"
Description
When reading a StringDType zarr array I sometimes obtain segmentation fault.
This depends on the way I index the data (i.e. which index of the array), but I'm always able to print the data of the whole array.
The error is quite hard to catch, and unfortunately makes my data nearly unusuable for now.
Context for the error.
- I created a zarr array with a StringDType.
- For reading the zarr array, I first load it into numpy using the
[:]
slicing, and then access the data by indexing the resulting numpy array. Copying the numpy array somehow changes where the error - printing the data of the full numpy array works
- However, sometimes, when slicing it, I obtain a segmentation fault on some (!) indices. And not always on the same - multi-index slicing always throws errors (e.g.
array[[6]]
), whereasarray[6]
is a bit inconsistent on whether it works or not.
Odd effects on attempted remedies
Copying the numpy array with new_array = np.copy(zarr_array[:])
at first seemed like a solution,
but in the end I had another segmentation fault pop up somewhere else.
The same goes for other wrappers like np.array(zarr_array)
or zarr_array[:].astype(object)
etc.
If you try this on my code below, the error will no longer appear, but I can assure you that it still pops up in my codebase at some point.
Reproducibility
I could not reproduce the segfault with synthetic data.
I assume something went wrong during writing of the data.
I have however a zarr array within a LocalStore
that reliably reproduces the segfault.
I attached it (manually zipped the directory for upload, you need to manually unzip).
This zarr array has a single chunk. I altered all other indices (to anonymize the data), which did not affect
the offending faulty index.
The indices I overwrote that were faulty before, are not faulty anymore.
I observed the same/a similar segfault on different machines, within different docker environments (same zarr version). As tracking down segfaults is quite annoying in a large pipeline, I can not fully confirm it was the exact same issue / same file that caused it.
# /// script
# requires-python = "==3.11.11"
# dependencies = [
# "zarr==3.0.8",
# "numcodecs==0.15.1",
# ]
# ///
import faulthandler
faulthandler.enable()
import numpy as np
[event_description_anony.zip](https://github.com/user-attachments/files/20927786/event_description_anony.zip)
import zarr
def main():
# Create a temporary directory
zarr_array = zarr.open("./event_description_anony")
# I anonymized all other entries. As long as I dont touch index 6, the segmentation fault is reproducible.
# for i in range(zarr_array.shape[0]):
# if i < 6:
# zarr_array[i] = "DUMMYTEXT"
# if i > 6:
# zarr_array[i] = "DUMMYTEXT"
# this works without issues, direct access to zarr array
print(f"{zarr_array.dtype=}")
print(f"{zarr_array[6]=}")
print(f"{zarr_array[[6]]=}")
print(f"{zarr_array[[1,2,4,6]]=}")
# I've only observed this issue when first loading it into numpy
# np_array = np.copy(zarr_array[:])
np_array = zarr_array[:]
# this still works
for i in range(np_array.shape[0]):
np_array[i]
# this fails at [[6]]
for i in range(np_array.shape[0]):
print(f"{i}: {np_array[[i]]}")
if __name__ == "__main__":
main()
Additional output
Stack trace of above code using the python faulthandler.
/root/.cache/uv/environments-v2/debug-zarr-0f1cac5393ffd124/lib/python3.11/site-packages/zarr/codecs/vlen_utf8.py:44: UserWarning: The codec `vlen-utf8` is currently not part in the Zarr format 3 specification. It may not be supported by other zarr implementations and may change in the future.
return cls(**configuration_parsed)
zarr_array.dtype=StringDType()
zarr_array[6]=array(['[comment] Look left and right 5 times'], dtype=StringDType())
zarr_array[[6]]=array([['[comment] Look left and right 5 times']], dtype=StringDType())
zarr_array[[1,2,4,6]]=array([['DUMMYTEXT'],
['DUMMYTEXT'],
['DUMMYTEXT'],
['[comment] Look left and right 5 times']], dtype=StringDType())
np_array[1]=array(['DUMMYTEXT'], dtype=StringDType())
np_array[2]=array(['DUMMYTEXT'], dtype=StringDType())
np_array[3]=array(['DUMMYTEXT'], dtype=StringDType())
np_array[4]=array(['DUMMYTEXT'], dtype=StringDType())
np_array[5]=array(['DUMMYTEXT'], dtype=StringDType())
np_array[6]=array(['[comment] Look left and right 5 times'], dtype=StringDType())
Fatal Python error: Segmentation fault
Thread 0x00007f64411db640 (most recent call first):
File "/opt/conda/lib/python3.11/concurrent/futures/thread.py", line 81 in _worker
File "/opt/conda/lib/python3.11/threading.py", line 982 in run
File "/opt/conda/lib/python3.11/threading.py", line 1045 in _bootstrap_inner
File "/opt/conda/lib/python3.11/threading.py", line 1002 in _bootstrap
Thread 0x00007f64419e0640 (most recent call first):
File "/opt/conda/lib/python3.11/concurrent/futures/thread.py", line 81 in _worker
File "/opt/conda/lib/python3.11/threading.py", line 982 in run
File "/opt/conda/lib/python3.11/threading.py", line 1045 in _bootstrap_inner
File "/opt/conda/lib/python3.11/threading.py", line 1002 in _bootstrap
Thread 0x00007f64421e5640 (most recent call first):
File "/opt/conda/lib/python3.11/selectors.py", line 468 in select
File "/opt/conda/lib/python3.11/asyncio/base_events.py", line 1898 in _run_once
File "/opt/conda/lib/python3.11/asyncio/base_events.py", line 608 in run_forever
File "/opt/conda/lib/python3.11/threading.py", line 982 in run
File "/opt/conda/lib/python3.11/threading.py", line 1045 in _bootstrap_inner
File "/opt/conda/lib/python3.11/threading.py", line 1002 in _bootstrap
Current thread 0x00007f647803f740 (most recent call first):
File "/workspace/debug_zarr.py", line 47 in main
File "/workspace/debug_zarr.py", line 51 in <module>
Extension modules: numpy._core._multiarray_umath, numpy.linalg._umath_linalg, yaml._yaml, numcodecs.compat_ext, numcodecs.blosc, numcodecs.zstd, numcodecs.lz4, numcodecs._shuffle, numcodecs.jenkins, crc32c._crc32c, numcodecs.vlen, numcodecs.fletcher32 (total: 12)