Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Segmentation Fault when importing duckdb on x86 running MacOS 11 #12199

Closed
2 tasks done
nikosk opened this issue May 23, 2024 · 16 comments
Closed
2 tasks done

Python: Segmentation Fault when importing duckdb on x86 running MacOS 11 #12199

nikosk opened this issue May 23, 2024 · 16 comments

Comments

@nikosk
Copy link

nikosk commented May 23, 2024

What happens?

Getting segmentation fault: 11 errors when importing the duckdb package

To Reproduce

The environment is MacOs 11.7.10 (x86), Python 3.8.19 (and 3.12.3) installed through asdf.

Minimal reproduction

import duckdb
duckdb.sql("SELECT 42").show()

Trace:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x800000003)
  * frame #0: 0x0000000104225e43 duckdb.cpython-38-darwin.so`std::__1::__hash_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::type_index, pybind11::detail::type_info*>, void*>*> std::__1::__hash_table<std::__1::__hash_value_type<std::__1::type_index, pybind11::detail::type_info*>, std::__1::__unordered_map_hasher<std::__1::type_index, std::__1::__hash_value_type<std::__1::type_index, pybind11::detail::type_info*>, pybind11::detail::type_hash, pybind11::detail::type_equal_to, true>, std::__1::__unordered_map_equal<std::__1::type_index, std::__1::__hash_value_type<std::__1::type_index, pybind11::detail::type_info*>, pybind11::detail::type_equal_to, pybind11::detail::type_hash, true>, std::__1::allocator<std::__1::__hash_value_type<std::__1::type_index, pybind11::detail::type_info*> > >::find<std::__1::type_index>(std::__1::type_index const&) + 35
    frame #1: 0x000000010422c9fc duckdb.cpython-38-darwin.so`pybind11::detail::generic_type::initialize(pybind11::detail::type_record const&) + 172
    frame #2: 0x000000010422a633 duckdb.cpython-38-darwin.so`pybind11::class_<duckdb::ExplainType>::class_<>(pybind11::handle, char const*) + 163
    frame #3: 0x000000010422a3c9 duckdb.cpython-38-darwin.so`pybind11::enum_<duckdb::ExplainType>::enum_<>(pybind11::handle const&, char const*) + 41
    frame #4: 0x000000010421a27b duckdb.cpython-38-darwin.so`duckdb::pybind11_init_duckdb(pybind11::module_&) + 59
    frame #5: 0x0000000104219b0f duckdb.cpython-38-darwin.so`PyInit_duckdb + 143
    frame #6: 0x0000000100258b65 libpython3.8.dylib`_PyImport_LoadDynamicModuleWithSpec + 613
    frame #7: 0x0000000100258410 libpython3.8.dylib`_imp_create_dynamic + 336
    frame #8: 0x000000010018a551 libpython3.8.dylib`cfunction_vectorcall_FASTCALL + 177
    frame #9: 0x000000010014b904 libpython3.8.dylib`PyVectorcall_Call + 100
    frame #10: 0x0000000100228967 libpython3.8.dylib`_PyEval_EvalFrameDefault + 31095
    frame #11: 0x000000010022cdf7 libpython3.8.dylib`_PyEval_EvalCodeWithName + 3287
    frame #12: 0x000000010014c0ed libpython3.8.dylib`_PyFunction_Vectorcall + 253
    frame #13: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #14: 0x0000000100228446 libpython3.8.dylib`_PyEval_EvalFrameDefault + 29782
    frame #15: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #16: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #17: 0x0000000100228429 libpython3.8.dylib`_PyEval_EvalFrameDefault + 29753
    frame #18: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #19: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #20: 0x00000001002284fa libpython3.8.dylib`_PyEval_EvalFrameDefault + 29962
    frame #21: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #22: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #23: 0x00000001002284fa libpython3.8.dylib`_PyEval_EvalFrameDefault + 29962
    frame #24: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #25: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #26: 0x00000001002284fa libpython3.8.dylib`_PyEval_EvalFrameDefault + 29962
    frame #27: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #28: 0x000000010014d99b libpython3.8.dylib`object_vacall + 459
    frame #29: 0x000000010014dbd3 libpython3.8.dylib`_PyObject_CallMethodIdObjArgs + 227
    frame #30: 0x00000001002572f8 libpython3.8.dylib`PyImport_ImportModuleLevelObject + 1800
    frame #31: 0x000000010021d459 libpython3.8.dylib`builtin___import__ + 137
    frame #32: 0x000000010014bb6a libpython3.8.dylib`cfunction_call_varargs + 122
    frame #33: 0x0000000100228967 libpython3.8.dylib`_PyEval_EvalFrameDefault + 31095
    frame #34: 0x000000010022cdf7 libpython3.8.dylib`_PyEval_EvalCodeWithName + 3287
    frame #35: 0x000000010014c0ed libpython3.8.dylib`_PyFunction_Vectorcall + 253
    frame #36: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #37: 0x00000001002284fa libpython3.8.dylib`_PyEval_EvalFrameDefault + 29962
    frame #38: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #39: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #40: 0x00000001002284fa libpython3.8.dylib`_PyEval_EvalFrameDefault + 29962
    frame #41: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #42: 0x000000010014d99b libpython3.8.dylib`object_vacall + 459
    frame #43: 0x000000010014dbd3 libpython3.8.dylib`_PyObject_CallMethodIdObjArgs + 227
    frame #44: 0x00000001002572f8 libpython3.8.dylib`PyImport_ImportModuleLevelObject + 1800
    frame #45: 0x0000000100226a9d libpython3.8.dylib`_PyEval_EvalFrameDefault + 23213
    frame #46: 0x000000010022cdf7 libpython3.8.dylib`_PyEval_EvalCodeWithName + 3287
    frame #47: 0x0000000100220f50 libpython3.8.dylib`PyEval_EvalCode + 48
    frame #48: 0x000000010021e390 libpython3.8.dylib`builtin_exec + 592
    frame #49: 0x000000010018a551 libpython3.8.dylib`cfunction_vectorcall_FASTCALL + 177
    frame #50: 0x000000010014b904 libpython3.8.dylib`PyVectorcall_Call + 100
    frame #51: 0x0000000100228967 libpython3.8.dylib`_PyEval_EvalFrameDefault + 31095
    frame #52: 0x000000010022cdf7 libpython3.8.dylib`_PyEval_EvalCodeWithName + 3287
    frame #53: 0x000000010014c0ed libpython3.8.dylib`_PyFunction_Vectorcall + 253
    frame #54: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #55: 0x0000000100228446 libpython3.8.dylib`_PyEval_EvalFrameDefault + 29782
    frame #56: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #57: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #58: 0x0000000100228429 libpython3.8.dylib`_PyEval_EvalFrameDefault + 29753
    frame #59: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #60: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #61: 0x00000001002284fa libpython3.8.dylib`_PyEval_EvalFrameDefault + 29962
    frame #62: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #63: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #64: 0x00000001002284fa libpython3.8.dylib`_PyEval_EvalFrameDefault + 29962
    frame #65: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #66: 0x000000010014d99b libpython3.8.dylib`object_vacall + 459
    frame #67: 0x000000010014dbd3 libpython3.8.dylib`_PyObject_CallMethodIdObjArgs + 227
    frame #68: 0x00000001002572f8 libpython3.8.dylib`PyImport_ImportModuleLevelObject + 1800
    frame #69: 0x0000000100226a9d libpython3.8.dylib`_PyEval_EvalFrameDefault + 23213
    frame #70: 0x000000010022cdf7 libpython3.8.dylib`_PyEval_EvalCodeWithName + 3287
    frame #71: 0x0000000100220f50 libpython3.8.dylib`PyEval_EvalCode + 48
    frame #72: 0x000000010021e390 libpython3.8.dylib`builtin_exec + 592
    frame #73: 0x000000010018a551 libpython3.8.dylib`cfunction_vectorcall_FASTCALL + 177
    frame #74: 0x000000010014b904 libpython3.8.dylib`PyVectorcall_Call + 100
    frame #75: 0x0000000100228967 libpython3.8.dylib`_PyEval_EvalFrameDefault + 31095
    frame #76: 0x000000010022cdf7 libpython3.8.dylib`_PyEval_EvalCodeWithName + 3287
    frame #77: 0x000000010014c0ed libpython3.8.dylib`_PyFunction_Vectorcall + 253
    frame #78: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #79: 0x0000000100228446 libpython3.8.dylib`_PyEval_EvalFrameDefault + 29782
    frame #80: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #81: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #82: 0x0000000100228429 libpython3.8.dylib`_PyEval_EvalFrameDefault + 29753
    frame #83: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #84: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #85: 0x00000001002284fa libpython3.8.dylib`_PyEval_EvalFrameDefault + 29962
    frame #86: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #87: 0x000000010022bd72 libpython3.8.dylib`call_function + 354
    frame #88: 0x00000001002284fa libpython3.8.dylib`_PyEval_EvalFrameDefault + 29962
    frame #89: 0x000000010014bf6d libpython3.8.dylib`function_code_fastcall + 237
    frame #90: 0x000000010014d99b libpython3.8.dylib`object_vacall + 459
    frame #91: 0x000000010014dbd3 libpython3.8.dylib`_PyObject_CallMethodIdObjArgs + 227
    frame #92: 0x00000001002572f8 libpython3.8.dylib`PyImport_ImportModuleLevelObject + 1800
    frame #93: 0x0000000100226a9d libpython3.8.dylib`_PyEval_EvalFrameDefault + 23213
    frame #94: 0x000000010022cdf7 libpython3.8.dylib`_PyEval_EvalCodeWithName + 3287
    frame #95: 0x0000000100220f50 libpython3.8.dylib`PyEval_EvalCode + 48
    frame #96: 0x000000010027178f libpython3.8.dylib`PyRun_SimpleFileExFlags + 911
    frame #97: 0x0000000100290bd3 libpython3.8.dylib`Py_RunMain + 2147
    frame #98: 0x00000001002910e3 libpython3.8.dylib`pymain_main + 403
    frame #99: 0x000000010029113b libpython3.8.dylib`Py_BytesMain + 43
    frame #100: 0x00007fff2054af3d libdyld.dylib`start + 1
    frame #101: 0x00007fff2054af3d libdyld.dylib`start + 1

OS:

MacOS 11.17.10

DuckDB Version:

0.10.3

DuckDB Client:

Python

Full Name:

Nikos Kastamoulas

Affiliation:

None/Personal Project

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a nightly build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have
@Tishj
Copy link
Contributor

Tishj commented May 23, 2024

11 errors

Can you provide these?

@nikosk
Copy link
Author

nikosk commented May 23, 2024

@Tishj The "11" number is the error code. The error message is literally this: Segmentation fault: 11

Btw, I chased it down and it looks like this is a regression. Version 0.10.2 does not display this behavior.

@nikosk
Copy link
Author

nikosk commented May 23, 2024

Some more information that might be relevant:

The earliest version that causes the seg fault is 0.10.3.dev848. Digging around in the changelog I found a PR that changes the files where the crash appears.

It looks like there was a change between versions 0.10.2 and 0.10.3 in how the python stubs are generated and for some reason it causes a segfault on my setup.

@Mytherin
Copy link
Collaborator

Mytherin commented May 23, 2024

I've tried to reproduce this using asdf on my Mac (although it is an ARM model), and everything seems to work as expected:

asdf install python 3.8.19
asdf global python 3.8.19
asdf exec python -m pip install duckdb
asdf exec python

```py
>>> import duckdb
>>> duckdb.sql('select 42')
┌───────┐
│  42   │
│ int32 │
├───────┤
│    42 │
└───────┘

Perhaps there are some existing packages this is conflicting with. Could you provide the list of installed packages and versions? Are you using a wheel build or a source build?

@nikosk
Copy link
Author

nikosk commented May 23, 2024

@Tishj hm, probably not it, I can reproduce this with only duckdb installed. Here's what pip list is reporting. I installed the package with pip install duckdb==0.10.3.dev848 (0.10.3.dev848 is the earliest version where this happens but the issue is present all the way up to the nightly build i.e. pip install --pre --upgrade duckdb ).

$ pip list
Package    Version
---------- -------------
duckdb     0.10.3.dev848
pip        24.0
setuptools 69.5.1
wheel      0.43.0

@Mytherin
Copy link
Collaborator

Just to confirm you are using the wheel builds right? (e.g. if you try running python3 -m pip install duckdb --only-binary=:all: it succeeds)?

@nikosk
Copy link
Author

nikosk commented May 23, 2024

@Mytherin hey, yes it succeeds:

python3 -m pip install duckdb --only-binary=:all:
Collecting duckdb
  Using cached duckdb-0.10.3-cp38-cp38-macosx_10_9_x86_64.whl.metadata (763 bytes)
Using cached duckdb-0.10.3-cp38-cp38-macosx_10_9_x86_64.whl (15.5 MB)
Installing collected packages: duckdb
Successfully installed duckdb-0.10.3

@Mytherin
Copy link
Collaborator

Do you have pybind11 installed locally? If so what is the version? (pybind11-config --version)?

@nikosk
Copy link
Author

nikosk commented May 23, 2024

@Mytherin no pybind

pybind11-config --version
bash: pybind11-config: command not found

@cmdlineluser
Copy link
Contributor

cmdlineluser commented May 23, 2024

I can replicate this on an older (non-updated) x86_64 mac.

0.10.3.dev848 wheel or later segfaults Python on import.

(Creating a wheel locally from a source build works without error.)

Is there anything I can do to help with debugging?

@Tishj
Copy link
Contributor

Tishj commented May 23, 2024

Can you try this to troubleshoot?

You say this crashes:

import duckdb
duckdb.sql("select 42")

Does this also crash?

import duckdb
duckdb.default_connection.sql("select 42")
import duckdb
con = duckdb.connect()
con.sql("select 42")

@Tishj
Copy link
Contributor

Tishj commented May 23, 2024

@cmdlineluser Could you also try these snippets and report your results?

@cmdlineluser
Copy link
Contributor

cmdlineluser commented May 23, 2024

@Tishj It's the import duckdb that segfaults.

$ python3 -m pip install duckdb -U --force-reinstall --only-binary=:all:
Collecting duckdb
  Using cached duckdb-0.10.3-cp310-cp310-macosx_10_9_x86_64.whl.metadata (763 bytes)
Installing collected packages: duckdb
  Attempting uninstall: duckdb
    Found existing installation: duckdb 0.10.2
    Uninstalling duckdb-0.10.2:
      Successfully uninstalled duckdb-0.10.2
Successfully installed duckdb-0.10.3
$ python3
Python 3.10.9 (main, Jan 14 2023, 16:56:26) [Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import duckdb
Segmentation fault: 11

(This is on an older mac that cannot be updated.)

@Mytherin Mytherin changed the title Python: Segmentation Fault when importing duckdb Python: Segmentation Fault when importing duckdb on old x86 mac May 23, 2024
@Mytherin Mytherin changed the title Python: Segmentation Fault when importing duckdb on old x86 mac Python: Segmentation Fault when importing duckdb on x86 running MacOS 11 May 23, 2024
@Mytherin
Copy link
Collaborator

Mytherin commented May 23, 2024

Could you try compiling from source using the --no-binary flag (python3 -m pip install duckdb --no-binary="duckdb")?

We've done some internal investigation and this seems to be related specifically to MacOS 11. It's also not limited to Python - and can also be triggered using the CLI. Since MacOS 11 is no longer supported by Apple itself, the problem could be that newer Apple build toolchains do not support MacOS 11 anymore or do not support it by default anymore and we might need to set specific flags for our binaries. Maybe building with the machine itself will circumvent the issue.

@nikosk
Copy link
Author

nikosk commented May 23, 2024

@Mytherin confirmed, the locally compiled version works without issues.

$ python3 -m pip install duckdb --no-binary="duckdb"
$ python3

Python 3.8.19 (default, May 23 2024, 09:16:31)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import duckdb
>>> duckdb.sql("SELECT 42").show()
┌───────┐
│  42   │
│ int32 │
├───────┤
│    42 │
└───────┘

@carlopi
Copy link
Contributor

carlopi commented May 24, 2024

This should be fixed via #12236, where we will provide pre-built wheels only for MacOS >= 12.0, and support for MacOS 11.0 will be via building from source.

Given MacOS 11 is mostly discontinued, I think this might be an OK stance.

Tonight set of nightly (available in about 6 hours) will be reviewed / tested some more, but I expect that PR to solve this issue.

Thanks for raising this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants