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 pyarrow is imported in exit handler #38626

Closed
gusostow opened this issue Nov 7, 2023 · 6 comments · Fixed by #38637
Closed

[Python] Segmentation fault when pyarrow is imported in exit handler #38626

gusostow opened this issue Nov 7, 2023 · 6 comments · Fixed by #38637
Assignees
Labels
Component: Python Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data. Type: bug
Milestone

Comments

@gusostow
Copy link

gusostow commented Nov 7, 2023

Describe the bug, including details regarding any error messages, version, and platform.

# example.py

import atexit

def exit(): import pyarrow

atexit.register(exit)
python example.py
[1]    2741781 segmentation fault (core dumped)  python example.py

Versions

libarrow                  13.0.0          h3b6bca8_14_cpu    conda-forge
pandas                    2.1.2                    pypi_0    pypi
pyarrow                   13.0.0                   pypi_0    pypi
python                    3.11.6          hab00c5b_0_cpython    conda-forge
python_abi                3.11                    4_cp311    conda-forge

Component(s)

Python

@kou kou changed the title Segementation fault when pyarrow is imported in exit handler [Python] Segementation fault when pyarrow is imported in exit handler Nov 7, 2023
@kou
Copy link
Member

kou commented Nov 7, 2023

Why do you want to do this...?

@gusostow
Copy link
Author

gusostow commented Nov 8, 2023

Exit handlers in a complex codebase might incidentally import pyarrow especially via pandas.

@jorisvandenbossche
Copy link
Member

I can confirm the segfault, both with pyarrow 13.0 and main from a few days ago. The gdb bactrace:

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x0000555555737cdc in new_threadstate (interp=0x0, init=init@entry=1) at /usr/local/src/conda/python-3.10.6/Python/pystate.c:616
616	/usr/local/src/conda/python-3.10.6/Python/pystate.c: No such file or directory.
(gdb) bt
#0  0x0000555555737cdc in new_threadstate (interp=0x0, init=init@entry=1) at /usr/local/src/conda/python-3.10.6/Python/pystate.c:616
#1  0x00005555555fa7ce in PyThreadState_New (interp=<optimized out>) at /usr/local/src/conda/python-3.10.6/Python/pystate.c:684
#2  PyGILState_Ensure () at /usr/local/src/conda/python-3.10.6/Python/pystate.c:1504
#3  0x00007ffff6d183f7 in arrow::py::PyAcquireGIL::acquire (this=<synthetic pointer>) at /home/joris/scipy/repos/arrow/python/pyarrow/src/arrow/python/common.h:115
#4  arrow::py::PyAcquireGIL::acquire (this=<synthetic pointer>) at /home/joris/scipy/repos/arrow/python/pyarrow/src/arrow/python/common.h:113
#5  arrow::py::PyAcquireGIL::PyAcquireGIL (this=<synthetic pointer>) at /home/joris/scipy/repos/arrow/python/pyarrow/src/arrow/python/common.h:109
#6  arrow::py::OwnedRefNoGIL::~OwnedRefNoGIL (this=0x555555e35b38, __in_chrg=<optimized out>) at /home/joris/scipy/repos/arrow/python/pyarrow/src/arrow/python/common.h:233
#7  arrow::py::OwnedRefNoGIL::~OwnedRefNoGIL (this=0x555555e35b38, __in_chrg=<optimized out>) at /home/joris/scipy/repos/arrow/python/pyarrow/src/arrow/python/common.h:227
#8  arrow::py::PyExtensionType::~PyExtensionType (this=0x555555e35ac0, __in_chrg=<optimized out>) at /home/joris/scipy/repos/arrow/python/pyarrow/src/arrow/python/extension_type.h:31
#9  arrow::py::PyExtensionType::~PyExtensionType (this=0x555555e35ac0, __in_chrg=<optimized out>) at /home/joris/scipy/repos/arrow/python/pyarrow/src/arrow/python/extension_type.h:31
#10 0x00007ffff5684815 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x555555e79bc0)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr_base.h:158
#11 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x555555e62a20, __in_chrg=<optimized out>)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr_base.h:736
#12 std::__shared_ptr<arrow::ExtensionType, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x555555e62a18, __in_chrg=<optimized out>)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr_base.h:1188
#13 std::shared_ptr<arrow::ExtensionType>::~shared_ptr (this=0x555555e62a18, __in_chrg=<optimized out>) at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr.h:121
#14 std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >::~pair (this=0x555555e629f8, __in_chrg=<optimized out>)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/stl_pair.h:211
#15 __gnu_cxx::new_allocator<std::__detail::_Hash_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, true> >::destroy<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > > (__p=0x555555e629f8, this=<optimized out>)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/ext/new_allocator.h:162
#16 std::allocator_traits<std::allocator<std::__detail::_Hash_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, true> > >::destroy<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > > (__p=0x555555e629f8, __a=...)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/alloc_traits.h:531
#17 std::__detail::_Hashtable_alloc<std::allocator<std::__detail::_Hash_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, true> > >::_M_deallocate_node (__n=0x555555e629f0, this=<optimized out>) at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/hashtable_policy.h:2054
#18 std::__detail::_Hashtable_alloc<std::allocator<std::__detail::_Hash_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, true> > >::_M_deallocate_nodes (this=<optimized out>, __n=0x555555d68f00) at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/hashtable_policy.h:2076
#19 std::_Hashtable<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > >, std::__detail::_Select1st, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::clear (this=0x555555e58450)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/hashtable.h:2085
#20 std::_Hashtable<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > >, std::__detail::_Select1st, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::~_Hashtable (this=0x555555e58450, __in_chrg=<optimized out>)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/hashtable.h:1442
#21 std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::shared_ptr<arrow::ExtensionType>, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > > >::~unordered_map (this=0x555555e58450, __in_chrg=<optimized out>)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/unordered_map.h:102
#22 arrow::ExtensionTypeRegistryImpl::~ExtensionTypeRegistryImpl (this=0x555555e58420, __in_chrg=<optimized out>) at /home/joris/scipy/repos/arrow/cpp/src/arrow/extension_type.cc:97
#23 0x00007ffff5684a5a in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x555555e58410)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr_base.h:158
#24 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=<optimized out>, __in_chrg=<optimized out>)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr_base.h:736
#25 std::__shared_ptr<arrow::ExtensionTypeRegistry, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=<optimized out>, __in_chrg=<optimized out>)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr_base.h:1188
#26 std::shared_ptr<arrow::ExtensionTypeRegistry>::~shared_ptr (this=<optimized out>, __in_chrg=<optimized out>)
    at /home/joris/miniconda3/envs/arrow-dev/x86_64-conda-linux-gnu/include/c++/10.4.0/bits/shared_ptr.h:121

@jorisvandenbossche
Copy link
Member

General cpython issue about issues with threads in finalization: python/cpython#80657 (cc @pitrou)

We do have some protection around acquiring the GIL here, but so that is not sufficient:

~OwnedRefNoGIL() {
// This destructor may be called after the Python interpreter is finalized.
// At least avoid spurious attempts to take the GIL when not necessary.
if (obj() == NULLPTR) {
return;
}
PyAcquireGIL lock;
reset();
}

@pitrou
Copy link
Member

pitrou commented Nov 8, 2023

@jorisvandenbossche Is it the full backtrace? Are there other threads running?

@pitrou
Copy link
Member

pitrou commented Nov 8, 2023

Ok, here is the full backtrace:

#0  0x0000555555724ded in new_threadstate (interp=0x0, init=init@entry=1) at /usr/local/src/conda/python-3.10.12/Python/pystate.c:624
#1  0x00005555555fc6d2 in PyThreadState_New (interp=<optimized out>) at /usr/local/src/conda/python-3.10.12/Python/pystate.c:692
#2  PyGILState_Ensure () at /usr/local/src/conda/python-3.10.12/Python/pystate.c:1512
#3  0x00007ffff66fa064 in arrow::py::PyAcquireGIL::acquire (this=0x7fffffffbaf0) at /home/antoine/arrow/dev/python/pyarrow/src/arrow/python/common.h:115
#4  0x00007ffff66fa025 in arrow::py::PyAcquireGIL::PyAcquireGIL (this=0x7fffffffbaf0) at /home/antoine/arrow/dev/python/pyarrow/src/arrow/python/common.h:109
#5  0x00007ffff66fa1e5 in arrow::py::OwnedRefNoGIL::~OwnedRefNoGIL (this=0x555555d905f8, __in_chrg=<optimized out>)
    at /home/antoine/arrow/dev/python/pyarrow/src/arrow/python/common.h:233
#6  0x00007ffff67b1c8b in arrow::py::PyExtensionType::~PyExtensionType (this=0x555555d90580, __in_chrg=<optimized out>)
    at /home/antoine/arrow/dev/python/pyarrow/src/arrow/python/extension_type.h:31
#7  0x00007ffff67b1cc4 in arrow::py::PyExtensionType::~PyExtensionType (this=0x555555d90580, __in_chrg=<optimized out>)
    at /home/antoine/arrow/dev/python/pyarrow/src/arrow/python/extension_type.h:31
#8  0x00007ffff67b23c8 in std::_Sp_counted_ptr<arrow::py::PyExtensionType*, (__gnu_cxx::_Lock_policy)2>::_M_dispose (this=0x555555e3c8c0)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:428
#9  0x00007ffff3a5f76b in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release_last_use (this=0x555555e3c8c0)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:175
#10 0x00007ffff3a5bfe0 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release_last_use_cold (this=0x555555e3c8c0)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:199
#11 0x00007ffff3a57327 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x555555e3c8c0)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:353
#12 0x00007ffff3a5c291 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x555555e489d0, __in_chrg=<optimized out>)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:1071
#13 0x00007ffff3e1e746 in std::__shared_ptr<arrow::ExtensionType, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x555555e489c8, __in_chrg=<optimized out>)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:1524
#14 0x00007ffff3e1e762 in std::shared_ptr<arrow::ExtensionType>::~shared_ptr (this=0x555555e489c8, __in_chrg=<optimized out>)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr.h:175
#15 0x00007ffff3e21b96 in std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >::~pair (this=0x555555e489a8, __in_chrg=<optimized out>) at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/stl_pair.h:185
#16 0x00007ffff3e21bc2 in std::__new_allocator<std::__detail::_Hash_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, true> >::destroy<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > > (this=0x555555bdf390, __p=0x555555e489a8)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/new_allocator.h:181
#17 0x00007ffff3e21453 in std::allocator_traits<std::allocator<std::__detail::_Hash_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, true> > >::destroy<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > > (__a=..., __p=0x555555e489a8)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/alloc_traits.h:535
#18 0x00007ffff3e208dd in std::__detail::_Hashtable_alloc<std::allocator<std::__detail::_Hash_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, true> > >::_M_deallocate_node (this=0x555555bdf390, __n=0x555555e489a0)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/hashtable_policy.h:1984
#19 0x00007ffff3e1ff70 in std::__detail::_Hashtable_alloc<std::allocator<std::__detail::_Hash_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, true> > >::_M_deallocate_nodes (this=0x555555bdf390, __n=0x555555e44120)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/hashtable_policy.h:2006
#20 0x00007ffff3e1f67b in std::_Hashtable<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > >, std::__detail::_Select1st, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::clear (
    this=0x555555bdf390) at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/hashtable.h:2500
#21 0x00007ffff3e1f145 in std::_Hashtable<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > >, std::__detail::_Select1st, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::~_Hashtable (
    this=0x555555bdf390, __in_chrg=<optimized out>) at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/hashtable.h:1584
#22 0x00007ffff3e1e45f in std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::shared_ptr<arrow::ExtensionType>, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::shared_ptr<arrow::ExtensionType> > > >::~unordered_map (this=0x555555bdf390, __in_chrg=<optimized out>)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/unordered_map.h:102
#23 0x00007ffff3e2237a in arrow::ExtensionTypeRegistryImpl::~ExtensionTypeRegistryImpl (this=0x555555bdf360, __in_chrg=<optimized out>)
    at /home/antoine/arrow/dev/cpp/src/arrow/extension_type.cc:97
#24 0x00007ffff3e22648 in std::_Destroy<arrow::ExtensionTypeRegistryImpl> (__pointer=0x555555bdf360)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/stl_construct.h:151
#25 0x00007ffff3e22626 in std::allocator_traits<std::allocator<void> >::destroy<arrow::ExtensionTypeRegistryImpl> (__p=0x555555bdf360)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/alloc_traits.h:648
#26 0x00007ffff3e224f5 in std::_Sp_counted_ptr_inplace<arrow::ExtensionTypeRegistryImpl, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose (
    this=0x555555bdf350) at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:613
#27 0x00007ffff3a5728b in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x555555bdf350)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:346
#28 0x00007ffff3a5c291 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x7ffff63f7d98 <arrow::g_registry+8>, __in_chrg=<optimized out>)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:1071
#29 0x00007ffff3e1e8e0 in std::__shared_ptr<arrow::ExtensionTypeRegistry, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x7ffff63f7d90 <arrow::g_registry>, 
    __in_chrg=<optimized out>) at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr_base.h:1524
#30 0x00007ffff3e1ed76 in std::shared_ptr<arrow::ExtensionTypeRegistry>::~shared_ptr (this=0x7ffff63f7d90 <arrow::g_registry>, __in_chrg=<optimized out>)
    at /home/antoine/mambaforge/envs/pyarrow/x86_64-conda-linux-gnu/include/c++/12.3.0/bits/shared_ptr.h:175
#31 0x00007ffff7cb5495 in __run_exit_handlers (status=0, listp=0x7ffff7e89838 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, 
    run_dtors=run_dtors@entry=true) at ./stdlib/exit.c:113
#32 0x00007ffff7cb5610 in __GI_exit (status=<optimized out>) at ./stdlib/exit.c:143
#33 0x00007ffff7c99d97 in __libc_start_call_main (main=main@entry=0x55555571f4e0 <main>, argc=argc@entry=3, argv=argv@entry=0x7fffffffc0b8)
    at ../sysdeps/nptl/libc_start_call_main.h:74
#34 0x00007ffff7c99e40 in __libc_start_main_impl (main=0x55555571f4e0 <main>, argc=3, argv=0x7fffffffc0b8, init=<optimized out>, fini=<optimized out>, 
    rtld_fini=<optimized out>, stack_end=0x7fffffffc0a8) at ../csu/libc-start.c:392
#35 0x000055555571f421 in _start ()

@pitrou pitrou self-assigned this Nov 8, 2023
@pitrou pitrou changed the title [Python] Segementation fault when pyarrow is imported in exit handler [Python] Segmentation fault when pyarrow is imported in exit handler Nov 8, 2023
pitrou added a commit to pitrou/arrow that referenced this issue Nov 8, 2023
…tdown

Some C++ destructors may be called after the Python interpreter has ceased to exist.
pitrou added a commit to pitrou/arrow that referenced this issue Nov 8, 2023
…tdown

Some C++ destructors may be called after the Python interpreter has ceased to exist.
jorisvandenbossche pushed a commit that referenced this issue Nov 14, 2023
…38637)

### Rationale for this change

Some C++ destructors may be called after the Python interpreter has ceased to exist.
If such a destructor tries to call back in the Python interpreter, for example by calling `Py_DECREF`, we get a crash.

### What changes are included in this PR?

Protect `OwnedRef` and `OwneRefNoGIL` destructors against decref'ing a Python object after Python finalization.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* Closes: #38626

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
@jorisvandenbossche jorisvandenbossche added this to the 15.0.0 milestone Nov 14, 2023
@raulcd raulcd modified the milestones: 15.0.0, 14.0.2 Nov 28, 2023
raulcd pushed a commit that referenced this issue Nov 28, 2023
…38637)

### Rationale for this change

Some C++ destructors may be called after the Python interpreter has ceased to exist.
If such a destructor tries to call back in the Python interpreter, for example by calling `Py_DECREF`, we get a crash.

### What changes are included in this PR?

Protect `OwnedRef` and `OwneRefNoGIL` destructors against decref'ing a Python object after Python finalization.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* Closes: #38626

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
@amoeba amoeba added the Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data. label Dec 7, 2023
dgreiss pushed a commit to dgreiss/arrow that referenced this issue Feb 19, 2024
…tdown (apache#38637)

### Rationale for this change

Some C++ destructors may be called after the Python interpreter has ceased to exist.
If such a destructor tries to call back in the Python interpreter, for example by calling `Py_DECREF`, we get a crash.

### What changes are included in this PR?

Protect `OwnedRef` and `OwneRefNoGIL` destructors against decref'ing a Python object after Python finalization.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* Closes: apache#38626

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Python Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data. Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants