benfred / py-spy

Sampling profiler for Python programs
MIT License
12.13k stars 401 forks source link

Seg fault on py-spy record --subprocesses #638

Open vinsonlu opened 7 months ago

vinsonlu commented 7 months ago

On MacOS with Python 3.11.5, I attempted to profile a program that uses the multiprocessing library to spawn Python worker subprocesses. I was running into the following error intermittently.

LLDB seg fault message:

* thread #7, stop reason = EXC_BAD_ACCESS (code=1, address=0xb9404e61294a1a63)
    frame #0: 0x00000001000037fc py-spy`core::ptr::drop_in_place$LT$remoteprocess..Error$GT$::hb302c8e3759652af + 308
py-spy`core::ptr::drop_in_place$LT$remoteprocess..Error$GT$::hb302c8e3759652af:
->  0x1000037fc <+308>: ldr    x8, [x22]
    0x100003800 <+312>: mov    x0, x20
    0x100003804 <+316>: blr    x8
    0x100003808 <+320>: b      0x100003728               ; <+96>
Target 0: (py-spy) stopped.

Backtrace from LLDB:

* thread #7, stop reason = EXC_BAD_ACCESS (code=1, address=0xb9404e61294a1a63)
  * frame #0: 0x00000001000037fc py-spy`core::ptr::drop_in_place$LT$remoteprocess..Error$GT$::hb302c8e3759652af + 308
    frame #1: 0x000000010000f590 py-spy`py_spy::python_spy::check_interpreter_addresses::hfcb2414a7e69b0a2 + 2116
    frame #2: 0x000000010000eccc py-spy`py_spy::python_spy::get_interpreter_address_from_binary::h2fdd239988accf41 + 112
    frame #3: 0x0000000100006fe4 py-spy`py_spy::python_spy::PythonSpy::new::h17e81b7888b2ba82 + 7844
    frame #4: 0x00000001000080f8 py-spy`py_spy::python_spy::PythonSpy::retry_new::h89af0b3beb257a9d + 112
    frame #5: 0x000000010004d2d0 py-spy`std::sys_common::backtrace::__rust_begin_short_backtrace::h3be0e086ee26e039 + 56
    frame #6: 0x0000000100062150 py-spy`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h1044a3385e2f94b7 + 268
    frame #7: 0x000000010020ba84 py-spy`std::sys::unix::thread::Thread::new::thread_start::h6244aa8f646b01ac [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::hee56534d4cc78b31 at boxed.rs:2007:9 [opt]
    frame #8: 0x000000010020ba78 py-spy`std::sys::unix::thread::Thread::new::thread_start::h6244aa8f646b01ac [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::hf1a328a6507f3fa7 at boxed.rs:2007:9 [opt]
    frame #9: 0x000000010020ba74 py-spy`std::sys::unix::thread::Thread::new::thread_start::h6244aa8f646b01ac at thread.rs:108:17 [opt]
    frame #10: 0x00000001855d3034 libsystem_pthread.dylib`_pthread_start + 136