Closed nirosys closed 7 months ago
Narrowed this down to a very trivial repro.
The missinggc
error is important, not because it's missing, but for some reason this pushes python into a state where the invalid address is poked. Running with gc
imported, does not end up resulting in a segfault.
$ cat trivial.py
import amazon.ion.simpleion as ion
print("C Extension Enabled? ", ion.c_ext)
ion_data = ion.loads("", text_buffer_size_limit=60000)
gc.collect()
$ python3 ./trivial.py
C Extension Enabled? True
Traceback (most recent call last):
File "/Users/glitch/Code/ion-python/./trivial.py", line 6, in <module>
gc.collect()
^^
NameError: name 'gc' is not defined. Did you forget to import 'gc'?
fish: Job 1, 'python3 ./trivial.py' terminated by signal SIGSEGV (Address boundary error)
$
This led me to examining the ionc_read
method closer, to see where a reference might be mishandled. I noticed the Py_XDECREF(text_buffer_size_limit)
and re-ran trivial.py without specifying a text_buffer_size_limit
. This ended up running without issue.
Looking at the documentation for PyArg_ParseTupleAndKeywords
the O
format does not create a strong reference for the object provided. This is the opposite behavior to O
when using PyArgs_BuildValue
. I must have read the build fmt section twice before realizing there was a separate section for parsing, and the fmts could have different behaviors.
Eliminating the XDECREF appears to have fixed the crash, and all of my tests show multiple loads are working fine in the tests that weren't previously.
There is an issue that seems to present when using multiple
loads
in a python session, or script, that results in a segmentation fault.Repro
At revision da632c1.
Investigation
Another stack trace, when reading a dataset that initially brought the issue to our attention.
Appears to be a reference counting issue.