chdb-io / chdb

chDB is an in-process OLAP SQL Engine 🚀 powered by ClickHouse
https://clickhouse.com/chdb
Apache License 2.0
2.13k stars 75 forks source link

Segfault on handled exceptions #40

Closed lmangani closed 1 year ago

lmangani commented 1 year ago

Error responses are causing core dumps on the latest version.

Example

The following query attempts to use a non-existing resource (could be local, remote, etc)

import chdb
url = "https://does.not.exist"
query = f"""SELECT * FROM url('{url}', Parquet) LIMIT 5 """
res = chdb.query(query, 'Dataframe')
print(str(res.get_memview().tobytes()))

The following cause is the expected exception:

Code: 198. DB::Exception: Not found address of host: donot.exist: Cannot extract table structure from Parquet format file. You can specify the structure manually. (DNS_ERROR)``

When using the latest chdb version (or any really) errors consistently cause a core dump after the error response which does not seem related to the chdb dynamic library but rather the python changes:

Code: 198. DB::Exception: Not found address of host: donot.exist: Cannot extract table structure from Parquet format file. You can specify the structure manually. (DNS_ERROR)
/arrow/python/pyarrow/src/arrow/python/common.cc:178:  Check failed: (data_) != (nullptr) Null pointer in Py_buffer
/usr/local/lib/python3.8/dist-packages/pyarrow/libarrow.so.1200(+0x1010758)[0x7fdd593b3758]
/usr/local/lib/python3.8/dist-packages/pyarrow/libarrow.so.1200(_ZN5arrow4util8ArrowLogD1Ev+0xed)[0x7fdd593b3b3d]
/usr/local/lib/python3.8/dist-packages/pyarrow/libarrow_python.so(_ZN5arrow2py8PyBuffer4InitEP7_object+0xf5)[0x7fdd95ee0815]
/usr/local/lib/python3.8/dist-packages/pyarrow/libarrow_python.so(_ZN5arrow2py8PyBuffer12FromPyObjectEP7_object+0x13a)[0x7fdd95ee096a]
/usr/local/lib/python3.8/dist-packages/pyarrow/lib.cpython-38-x86_64-linux-gnu.so(+0x1c5735)[0x7fdd85288735]
/usr/local/lib/python3.8/dist-packages/pyarrow/lib.cpython-38-x86_64-linux-gnu.so(+0xd033e)[0x7fdd8519333e]
/usr/local/lib/python3.8/dist-packages/pyarrow/lib.cpython-38-x86_64-linux-gnu.so(+0x15a10c)[0x7fdd8521d10c]
/usr/local/lib/python3.8/dist-packages/pyarrow/lib.cpython-38-x86_64-linux-gnu.so(+0xd033e)[0x7fdd8519333e]
/usr/local/lib/python3.8/dist-packages/pyarrow/lib.cpython-38-x86_64-linux-gnu.so(+0x1b70d4)[0x7fdd8527a0d4]
python3(PyCFunction_Call+0x59)[0x5f6939]
python3(_PyObject_MakeTpCall+0x296)[0x5f7506]
python3(_PyEval_EvalFrameDefault+0x6259)[0x571019]
python3(_PyEval_EvalCodeWithName+0x26a)[0x5697da]
python3[0x59c396]
python3(_PyObject_MakeTpCall+0x1ff)[0x5f746f]
python3(_PyEval_EvalFrameDefault+0x5dce)[0x570b8e]
python3(_PyFunction_Vectorcall+0x1b6)[0x5f6ce6]
python3(_PyEval_EvalFrameDefault+0x72d)[0x56b4ed]
python3(_PyFunction_Vectorcall+0x1b6)[0x5f6ce6]
python3(_PyEval_EvalFrameDefault+0x72d)[0x56b4ed]
python3(_PyEval_EvalCodeWithName+0x26a)[0x5697da]
python3(_PyFunction_Vectorcall+0x393)[0x5f6ec3]
python3(_PyEval_EvalFrameDefault+0x5796)[0x570556]
python3(_PyEval_EvalCodeWithName+0x26a)[0x5697da]
python3(PyEval_EvalCode+0x27)[0x68e547]
python3[0x67dbf1]
python3[0x67dc6f]
python3[0x67dd11]
python3(PyRun_SimpleFileExFlags+0x197)[0x67fe37]
python3(Py_RunMain+0x212)[0x6b7c82]
python3(Py_BytesMain+0x2d)[0x6b800d]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x7fddb3306083]
python3(_start+0x2e)[0x5fb85e]
Aborted (core dumped)

The same seems to apply to any error condition returned.

Opening for investigation.

auxten commented 1 year ago

Any SQL-caused error without content returned will cause this core dump.

lmangani commented 1 year ago

Is this ready for re-testing? Shall we release a 0.10.2 release?

auxten commented 1 year ago

One case is fixed, but there's another one need follow up. It can be reproduced by

python3 -c "import _chdb as chdb; chdb.query('Select version()', 'xxx')"