mozilla / cubeb-coreaudio-rs

The audio backend of Firefox on Mac OS X.
ISC License
24 stars 10 forks source link

intermittent crash when running cargo test #31

Open ChunMinChang opened 4 years ago

ChunMinChang commented 4 years ago

The cargo test crashes randomly.

Here is a log for the crash when running rust-lldb target/debug/deps/cubeb_coreaudio-*

Process 2001 stopped
* thread #24, name = 'backend::tests::api::test_set_channel_layout_input', stop reason = EXC_BAD_ACCESS (code=1, address=0xa)
    frame #0: 0x00007fff3c23e198 CoreFoundation`CFRelease + 11
CoreFoundation`CFRelease:
->  0x7fff3c23e198 <+11>: movq   0x8(%rdi), %rcx
    0x7fff3c23e19c <+15>: movq   (%rdi), %rax
    0x7fff3c23e19f <+18>: testq  %rax, %rax
    0x7fff3c23e1a2 <+21>: je     0x7fff3c23e1cb            ; <+62>
Target 0: (cubeb_coreaudio-fb8fa5520de9e09f) stopped.
(lldb) bt
error: need to add support for DW_TAG_base_type '()' encoded with DW_ATE = 0x7, bit_size = 0
* thread #24, name = 'backend::tests::api::test_set_channel_layout_input', stop reason = EXC_BAD_ACCESS (code=1, address=0xa)
  * frame #0: 0x00007fff3c23e198 CoreFoundation`CFRelease + 11
    frame #1: 0x0000000105bc2134 CoreAudio`___lldb_unnamed_symbol120$$CoreAudio + 34
    frame #2: 0x0000000105c5c300 CoreAudio`___lldb_unnamed_symbol2202$$CoreAudio + 14
    frame #3: 0x0000000105c5cbdf CoreAudio`___lldb_unnamed_symbol2210$$CoreAudio + 37
    frame #4: 0x0000000105be3115 CoreAudio`___lldb_unnamed_symbol672$$CoreAudio + 165
    frame #5: 0x0000000105cbdd2c CoreAudio`___lldb_unnamed_symbol3288$$CoreAudio + 30
    frame #6: 0x00007fff50950653 AudioToolboxCore`AudioComponentInstanceDispose + 58
    frame #7: 0x00000001000e3134 cubeb_coreaudio-fb8fa5520de9e09f`_$LT$cubeb_coreaudio..backend..tests..utils..TestAudioUnit$u20$as$u20$core..ops..drop..Drop$GT$::drop::hade0d12626f943fa(self=&0x70000a248788) at utils.rs:81:12
    frame #8: 0x00000001000c7bd5 cubeb_coreaudio-fb8fa5520de9e09f`core::ptr::real_drop_in_place::h9a4495cedf5ac709((null)=&0x70000a248788) at mod.rs:175
    frame #9: 0x000000010000ac7d cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_channel_layout_input::h69123317f82de5dc at api.rs:995:4
    frame #10: 0x00000001001096f1 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_channel_layout_input::_$u7b$$u7b$closure$u7d$$u7d$::h80a84f1d5587d4da((null)=&0x70000a2488c0) at api.rs:983
    frame #11: 0x00000001000c44f1 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once::hb3a5bff67965f914((null)=closure-0 {

}, (null)=<unavailable>) at function.rs:227:4
    frame #12: 0x00000001001272ae cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h62abc180af5184b6 at boxed.rs:922:8 [opt]
    frame #13: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #14: 0x0000000100140477 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panicking::try::hc6851a78b7283b60 at panicking.rs:271:12 [opt]
    frame #15: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panic::catch_unwind::h4f224793963be037 at panic.rs:394 [opt]
    frame #16: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b at lib.rs:1413 [opt]
    frame #17: 0x000000010011c915 cubeb_coreaudio-fb8fa5520de9e09f`std::sys_common::backtrace::__rust_begin_short_backtrace::h09f30e53b0d36855 at backtrace.rs:126:4 [opt]
    frame #18: 0x0000000100120ad5 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h11ad033de2bf23bd at mod.rs:470:16 [opt]
    frame #19: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] _$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hdfd84f2d534f6c68 at panic.rs:315 [opt]
    frame #20: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 at panicking.rs:292 [opt]
    frame #21: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #22: 0x0000000100121085 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panicking::try::h830b2026ed6a44c3 at panicking.rs:271:12 [opt]
    frame #23: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panic::catch_unwind::h8489ab8e1eca8899 at panic.rs:394 [opt]
    frame #24: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::hb9ab1346bf0aa0ce at mod.rs:469 [opt]
    frame #25: 0x0000000100121017 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 at function.rs:227 [opt]
    frame #26: 0x0000000100173c7e cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd1afe4d791e3679f at boxed.rs:922:8 [opt]
    frame #27: 0x000000010017fd9e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] _$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd175b6857cf77782 at boxed.rs:922:8 [opt]
    frame #28: 0x000000010017fd92 cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] std::sys_common::thread::start_thread::hed1d18da7acfc5a9 at thread.rs:13 [opt]
    frame #29: 0x000000010017fd1e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 at thread.rs:79 [opt]
    frame #30: 0x00007fff73b16e65 libsystem_pthread.dylib`_pthread_start + 148
    frame #31: 0x00007fff73b1283b libsystem_pthread.dylib`thread_start + 15
padenot commented 4 years ago

Does an ASAN build helps diagnosing this?

ChunMinChang commented 4 years ago

Another crash

Process 2962 stopped
* thread #23, name = 'backend::tests::api::test_set_channel_layout_output_undefind', stop reason = EXC_BAD_ACCESS (code=1, address=0x2)
    frame #0: 0x00000001053c53ee CoreAudio`___lldb_unnamed_symbol191$$CoreAudio + 190
CoreAudio`___lldb_unnamed_symbol191$$CoreAudio:
->  0x1053c53ee <+190>: movq   (%rdi), %rax
    0x1053c53f1 <+193>: callq  *0x8(%rax)
    0x1053c53f4 <+196>: movq   0x450(%r15), %rax
    0x1053c53fb <+203>: addq   $0x40, %rbx
Target 0: (cubeb_coreaudio-fb8fa5520de9e09f) stopped.
(lldb) bt
error: need to add support for DW_TAG_base_type '()' encoded with DW_ATE = 0x7, bit_size = 0
* thread #23, name = 'backend::tests::api::test_set_channel_layout_output_undefind', stop reason = EXC_BAD_ACCESS (code=1, address=0x2)
  * frame #0: 0x00000001053c53ee CoreAudio`___lldb_unnamed_symbol191$$CoreAudio + 190
    frame #1: 0x00000001054bdd2c CoreAudio`___lldb_unnamed_symbol3288$$CoreAudio + 30
    frame #2: 0x00007fff43404653 AudioToolboxCore`AudioComponentInstanceDispose + 58
    frame #3: 0x00000001000e3108 cubeb_coreaudio-fb8fa5520de9e09f`_$LT$cubeb_coreaudio..backend..tests..utils..TestAudioUnit$u20$as$u20$core..ops..drop..Drop$GT$::drop::hade0d12626f943fa(self=&0x70000e215788) at utils.rs:82:12
    frame #4: 0x00000001000c7b75 cubeb_coreaudio-fb8fa5520de9e09f`core::ptr::real_drop_in_place::h9a4495cedf5ac709((null)=&0x70000e215788) at mod.rs:175
    frame #5: 0x000000010000aa9d cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_channel_layout_output_undefind::hec27a3c807a609c4 at api.rs:978:4
    frame #6: 0x00000001001096d1 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_channel_layout_output_undefind::_$u7b$$u7b$closure$u7d$$u7d$::h8e01a3268f9caaa0((null)=&0x70000e2158c0) at api.rs:967
    frame #7: 0x00000001000c2771 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once::h16cd00c19ebec5c2((null)=closure-0 {

}, (null)=<unavailable>) at function.rs:227:4
    frame #8: 0x00000001001272ae cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h62abc180af5184b6 at boxed.rs:922:8 [opt]
    frame #9: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #10: 0x0000000100140477 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panicking::try::hc6851a78b7283b60 at panicking.rs:271:12 [opt]
    frame #11: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panic::catch_unwind::h4f224793963be037 at panic.rs:394 [opt]
    frame #12: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b at lib.rs:1413 [opt]
    frame #13: 0x000000010011c915 cubeb_coreaudio-fb8fa5520de9e09f`std::sys_common::backtrace::__rust_begin_short_backtrace::h09f30e53b0d36855 at backtrace.rs:126:4 [opt]
    frame #14: 0x0000000100120ad5 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h11ad033de2bf23bd at mod.rs:470:16 [opt]
    frame #15: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] _$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hdfd84f2d534f6c68 at panic.rs:315 [opt]
    frame #16: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 at panicking.rs:292 [opt]
    frame #17: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #18: 0x0000000100121085 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panicking::try::h830b2026ed6a44c3 at panicking.rs:271:12 [opt]
    frame #19: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panic::catch_unwind::h8489ab8e1eca8899 at panic.rs:394 [opt]
    frame #20: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::hb9ab1346bf0aa0ce at mod.rs:469 [opt]
    frame #21: 0x0000000100121017 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 at function.rs:227 [opt]
    frame #22: 0x0000000100173c7e cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd1afe4d791e3679f at boxed.rs:922:8 [opt]
    frame #23: 0x000000010017fd9e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] _$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd175b6857cf77782 at boxed.rs:922:8 [opt]
    frame #24: 0x000000010017fd92 cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] std::sys_common::thread::start_thread::hed1d18da7acfc5a9 at thread.rs:13 [opt]
    frame #25: 0x000000010017fd1e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 at thread.rs:79 [opt]
    frame #26: 0x00007fff665cae65 libsystem_pthread.dylib`_pthread_start + 148
    frame #27: 0x00007fff665c683b libsystem_pthread.dylib`thread_start + 15
(lldb) 
ChunMinChang commented 4 years ago

One more crash

Process 3478 stopped
* thread #19, name = 'backend::tests::api::test_for_create_audiounit', stop reason = EXC_BAD_ACCESS (code=1, address=0x2)
    frame #0: 0x0000000105bbb075 CoreAudio`___lldb_unnamed_symbol22$$CoreAudio + 197
CoreAudio`___lldb_unnamed_symbol22$$CoreAudio:
->  0x105bbb075 <+197>: movq   (%rdi), %rax
    0x105bbb078 <+200>: callq  *0x8(%rax)
    0x105bbb07b <+203>: movq   0x10(%r12), %rax
    0x105bbb080 <+208>: addq   $0x40, %rbx
Target 0: (cubeb_coreaudio-fb8fa5520de9e09f) stopped.
(lldb) bt
error: need to add support for DW_TAG_base_type '()' encoded with DW_ATE = 0x7, bit_size = 0
* thread #19, name = 'backend::tests::api::test_for_create_audiounit', stop reason = EXC_BAD_ACCESS (code=1, address=0x2)
  * frame #0: 0x0000000105bbb075 CoreAudio`___lldb_unnamed_symbol22$$CoreAudio + 197
    frame #1: 0x0000000105bba389 CoreAudio`___lldb_unnamed_symbol18$$CoreAudio + 1619
    frame #2: 0x0000000105bc3016 CoreAudio`___lldb_unnamed_symbol156$$CoreAudio + 86
    frame #3: 0x0000000105bbe35c CoreAudio`___lldb_unnamed_symbol41$$CoreAudio + 1736
    frame #4: 0x0000000105bbdaf7 CoreAudio`___lldb_unnamed_symbol40$$CoreAudio + 120
    frame #5: 0x00000001000476b9 cubeb_coreaudio-fb8fa5520de9e09f`coreaudio_sys_utils::audio_unit::audio_unit_set_property::h84579ed3f9615925(unit=&0x80d96231, property=2000, scope=0, element=0, data=&0x7000030da554, size=4) at audio_unit.rs:56:8
    frame #6: 0x0000000100052fbd cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::set_device_to_audiounit::h97b797d2ff0cc13b(unit=&0x80d96231, device_id=187) at mod.rs:1213:17
    frame #7: 0x0000000100052c5b cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::create_audiounit::h2a9d457fc8afcb68(device=&0x7000030da790) at mod.rs:1164:4
    frame #8: 0x000000010000c3a3 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_for_create_audiounit::h54ca9a753b57fcce at api.rs:1134:23
    frame #9: 0x0000000100109791 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_for_create_audiounit::_$u7b$$u7b$closure$u7d$$u7d$::h4c013928773bf997((null)=&0x7000030da8c0) at api.rs:1081
    frame #10: 0x00000001000c3501 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once::h66ce7b159d0e3609((null)=closure-0 {

}, (null)=<unavailable>) at function.rs:227:4
    frame #11: 0x000000010012728e cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h62abc180af5184b6 at boxed.rs:922:8 [opt]
    frame #12: 0x00000001001804ef cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #13: 0x0000000100140457 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panicking::try::hc6851a78b7283b60 at panicking.rs:271:12 [opt]
    frame #14: 0x0000000100140412 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panic::catch_unwind::h4f224793963be037 at panic.rs:394 [opt]
    frame #15: 0x0000000100140412 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b at lib.rs:1413 [opt]
    frame #16: 0x000000010011c8f5 cubeb_coreaudio-fb8fa5520de9e09f`std::sys_common::backtrace::__rust_begin_short_backtrace::h09f30e53b0d36855 at backtrace.rs:126:4 [opt]
    frame #17: 0x0000000100120ab5 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h11ad033de2bf23bd at mod.rs:470:16 [opt]
    frame #18: 0x0000000100120aa2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] _$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hdfd84f2d534f6c68 at panic.rs:315 [opt]
    frame #19: 0x0000000100120aa2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 at panicking.rs:292 [opt]
    frame #20: 0x00000001001804ef cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #21: 0x0000000100121065 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panicking::try::h830b2026ed6a44c3 at panicking.rs:271:12 [opt]
    frame #22: 0x000000010012102c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panic::catch_unwind::h8489ab8e1eca8899 at panic.rs:394 [opt]
    frame #23: 0x000000010012102c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::hb9ab1346bf0aa0ce at mod.rs:469 [opt]
    frame #24: 0x0000000100120ff7 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 at function.rs:227 [opt]
    frame #25: 0x0000000100173c5e cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd1afe4d791e3679f at boxed.rs:922:8 [opt]
    frame #26: 0x000000010017fd7e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] _$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd175b6857cf77782 at boxed.rs:922:8 [opt]
    frame #27: 0x000000010017fd72 cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] std::sys_common::thread::start_thread::hed1d18da7acfc5a9 at thread.rs:13 [opt]
    frame #28: 0x000000010017fcfe cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 at thread.rs:79 [opt]
    frame #29: 0x00007fff665cae65 libsystem_pthread.dylib`_pthread_start + 148
    frame #30: 0x00007fff665c683b libsystem_pthread.dylib`thread_start + 15
(lldb) 
ChunMinChang commented 4 years ago

Does an ASAN build helps diagnosing this?

I never turn on ASAN in rust before, but it looks like sanitizer is possible to be turned on in rust: https://github.com/japaric/rust-san

I'll try it to see if it helps! Thanks for the advice!

ChunMinChang commented 4 years ago

I'll try it to see if it helps! Thanks for the advice!

It seems that it only works on Linux now. Need to find another way to diagnose the problem...

ChunMinChang commented 4 years ago

Yet another crash

Process 4184 stopped
* thread #23, name = 'backend::tests::api::test_set_buffer_size_sync', stop reason = EXC_BAD_ACCESS (code=1, address=0x2)
    frame #0: 0x0000000105bc53aa CoreAudio`___lldb_unnamed_symbol191$$CoreAudio + 122
CoreAudio`___lldb_unnamed_symbol191$$CoreAudio:
->  0x105bc53aa <+122>: movq   (%rdi), %rax
    0x105bc53ad <+125>: callq  *0x8(%rax)
    0x105bc53b0 <+128>: movq   0x318(%r15), %rax
    0x105bc53b7 <+135>: addq   $0x40, %rbx
Target 0: (cubeb_coreaudio-fb8fa5520de9e09f) stopped.
(lldb) bt
* thread #23, name = 'backend::tests::api::test_set_buffer_size_sync', stop reason = EXC_BAD_ACCESS (code=1, address=0x2)
  * frame #0: 0x0000000105bc53aa CoreAudio`___lldb_unnamed_symbol191$$CoreAudio + 122
    frame #1: 0x0000000105cbdd2c CoreAudio`___lldb_unnamed_symbol3288$$CoreAudio + 30
    frame #2: 0x00007fff43404653 AudioToolboxCore`AudioComponentInstanceDispose + 58
    frame #3: 0x00000001000e3104 cubeb_coreaudio-fb8fa5520de9e09f`_$LT$cubeb_coreaudio..backend..tests..utils..TestAudioUnit$u20$as$u20$core..ops..drop..Drop$GT$::drop::hade0d12626f943fa(self=&0x70000cb716e0) at utils.rs:83:12
    frame #4: 0x00000001000c7b65 cubeb_coreaudio-fb8fa5520de9e09f`core::ptr::real_drop_in_place::h9a4495cedf5ac709((null)=&0x70000cb716e0) at mod.rs:175
    frame #5: 0x000000010000d056 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_buffer_size_sync::test_set_buffer_size_by_scope::h30a6f2074959836d(scope=Input) at api.rs:1273:4
    frame #6: 0x000000010000cab9 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_buffer_size_sync::h3e1961eacc403564 at api.rs:1245:4
    frame #7: 0x00000001001098b1 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_buffer_size_sync::_$u7b$$u7b$closure$u7d$$u7d$::h20fb2db9752844b9((null)=&0x70000cb718c0) at api.rs:1244
    frame #8: 0x00000001000c5381 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once::hfe560ebac0dea217((null)=closure-0 {

}, (null)=<unavailable>) at function.rs:227:4
    frame #9: 0x00000001001272ae cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h62abc180af5184b6 at boxed.rs:922:8 [opt]
    frame #10: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #11: 0x0000000100140477 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panicking::try::hc6851a78b7283b60 at panicking.rs:271:12 [opt]
    frame #12: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panic::catch_unwind::h4f224793963be037 at panic.rs:394 [opt]
    frame #13: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b at lib.rs:1413 [opt]
    frame #14: 0x000000010011c915 cubeb_coreaudio-fb8fa5520de9e09f`std::sys_common::backtrace::__rust_begin_short_backtrace::h09f30e53b0d36855 at backtrace.rs:126:4 [opt]
    frame #15: 0x0000000100120ad5 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h11ad033de2bf23bd at mod.rs:470:16 [opt]
    frame #16: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] _$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hdfd84f2d534f6c68 at panic.rs:315 [opt]
    frame #17: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 at panicking.rs:292 [opt]
    frame #18: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #19: 0x0000000100121085 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panicking::try::h830b2026ed6a44c3 at panicking.rs:271:12 [opt]
    frame #20: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panic::catch_unwind::h8489ab8e1eca8899 at panic.rs:394 [opt]
    frame #21: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::hb9ab1346bf0aa0ce at mod.rs:469 [opt]
    frame #22: 0x0000000100121017 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 at function.rs:227 [opt]
    frame #23: 0x0000000100173c7e cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd1afe4d791e3679f at boxed.rs:922:8 [opt]
    frame #24: 0x000000010017fd9e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] _$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd175b6857cf77782 at boxed.rs:922:8 [opt]
    frame #25: 0x000000010017fd92 cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] std::sys_common::thread::start_thread::hed1d18da7acfc5a9 at thread.rs:13 [opt]
    frame #26: 0x000000010017fd1e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 at thread.rs:79 [opt]
    frame #27: 0x00007fff665cae65 libsystem_pthread.dylib`_pthread_start + 148
    frame #28: 0x00007fff665c683b libsystem_pthread.dylib`thread_start + 15
(lldb) 
ChunMinChang commented 4 years ago

Get another crash and the reason is EXC_BAD_ACCESS (code=EXC_I386_GPFLT). EXC_I386_GPFLT is general protection fault. According to this discussion, it seems that the code uses a wrong memory address.

Process 5633 stopped
* thread #23, name = 'backend::tests::api::test_set_channel_layout_output_undefind', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x00007fff62c23454 libAudioToolboxUtility.dylib`BaseOpaqueObject::ResolveOpaqueRef(BaseOpaqueObject::RTTI const&, BaseOpaqueObject::Ref) + 50
libAudioToolboxUtility.dylib`BaseOpaqueObject::ResolveOpaqueRef:
->  0x7fff62c23454 <+50>: callq  *0x18(%rax)
    0x7fff62c23457 <+53>: movl   %eax, %ecx
    0x7fff62c23459 <+55>: xorl   %eax, %eax
    0x7fff62c2345b <+57>: testb  %cl, %cl
Target 0: (cubeb_coreaudio-fb8fa5520de9e09f) stopped.
(lldb) bt
error: need to add support for DW_TAG_base_type '()' encoded with DW_ATE = 0x7, bit_size = 0
* thread #23, name = 'backend::tests::api::test_set_channel_layout_output_undefind', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x00007fff62c23454 libAudioToolboxUtility.dylib`BaseOpaqueObject::ResolveOpaqueRef(BaseOpaqueObject::RTTI const&, BaseOpaqueObject::Ref) + 50
    frame #1: 0x00007fff432d9a48 AudioToolboxCore`APComponentInstance::FromOpaqueComponentInstance(OpaqueAudioComponentInstance*) + 32
    frame #2: 0x00007fff4340470d AudioToolboxCore`AudioComponentInstanceGetComponent + 31
    frame #3: 0x00000001063b9181 CoreAudio`___lldb_unnamed_symbol4$$CoreAudio + 159
    frame #4: 0x00000001063e2d37 CoreAudio`___lldb_unnamed_symbol670$$CoreAudio + 61
    frame #5: 0x00000001063c28b8 CoreAudio`___lldb_unnamed_symbol137$$CoreAudio + 24
    frame #6: 0x00000001063c55f2 CoreAudio`___lldb_unnamed_symbol196$$CoreAudio + 50
    frame #7: 0x00000001063faec5 CoreAudio`___lldb_unnamed_symbol1044$$CoreAudio + 21
    frame #8: 0x00000001064bdc69 CoreAudio`___lldb_unnamed_symbol3287$$CoreAudio + 77
    frame #9: 0x00007fff43315f2a AudioToolboxCore`APComponent::newInstance(unsigned int, bool, void (OpaqueAudioComponentInstance*, int) block_pointer) + 1986
    frame #10: 0x00007fff43404549 AudioToolboxCore`__AudioComponentInstanceNew_block_invoke + 88
    frame #11: 0x00007fff432bebb8 AudioToolboxCore`Synchronously + 87
    frame #12: 0x00007fff4340445f AudioToolboxCore`AudioComponentInstanceNew + 183
    frame #13: 0x00000001000e368e cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::utils::test_create_audiounit::h4162221d51a14e13(unit_type=HALOutput) at utils.rs:156:26
    frame #14: 0x00000001000e319d cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::utils::test_get_default_audiounit::h9ee676265cf376a4(scope=Output) at utils.rs:92:15
    frame #15: 0x000000010000a8e6 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_channel_layout_output_undefind::hec27a3c807a609c4 at api.rs:977:24
    frame #16: 0x00000001001096d1 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_channel_layout_output_undefind::_$u7b$$u7b$closure$u7d$$u7d$::h8e01a3268f9caaa0((null)=&0x70000d7848c0) at api.rs:976
    frame #17: 0x00000001000c2781 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once::h16cd00c19ebec5c2((null)=closure-0 {

}, (null)=<unavailable>) at function.rs:227:4
    frame #18: 0x00000001001272ae cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h62abc180af5184b6 at boxed.rs:922:8 [opt]
    frame #19: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #20: 0x0000000100140477 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panicking::try::hc6851a78b7283b60 at panicking.rs:271:12 [opt]
    frame #21: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panic::catch_unwind::h4f224793963be037 at panic.rs:394 [opt]
    frame #22: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b at lib.rs:1413 [opt]
    frame #23: 0x000000010011c915 cubeb_coreaudio-fb8fa5520de9e09f`std::sys_common::backtrace::__rust_begin_short_backtrace::h09f30e53b0d36855 at backtrace.rs:126:4 [opt]
    frame #24: 0x0000000100120ad5 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h11ad033de2bf23bd at mod.rs:470:16 [opt]
    frame #25: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] _$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hdfd84f2d534f6c68 at panic.rs:315 [opt]
    frame #26: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 at panicking.rs:292 [opt]
    frame #27: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #28: 0x0000000100121085 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panicking::try::h830b2026ed6a44c3 at panicking.rs:271:12 [opt]
    frame #29: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panic::catch_unwind::h8489ab8e1eca8899 at panic.rs:394 [opt]
    frame #30: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::hb9ab1346bf0aa0ce at mod.rs:469 [opt]
    frame #31: 0x0000000100121017 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 at function.rs:227 [opt]
    frame #32: 0x0000000100173c7e cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd1afe4d791e3679f at boxed.rs:922:8 [opt]
    frame #33: 0x000000010017fd9e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] _$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd175b6857cf77782 at boxed.rs:922:8 [opt]
    frame #34: 0x000000010017fd92 cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] std::sys_common::thread::start_thread::hed1d18da7acfc5a9 at thread.rs:13 [opt]
    frame #35: 0x000000010017fd1e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 at thread.rs:79 [opt]
    frame #36: 0x00007fff665cae65 libsystem_pthread.dylib`_pthread_start + 148
    frame #37: 0x00007fff665c683b libsystem_pthread.dylib`thread_start + 15
(lldb) 
ChunMinChang commented 4 years ago

The crash happens when AudioComponentInstanceDispose, AudioUnitSetProperty, or AudioComponentInstanceNew is called.

I have a feeling that the AudioUnit object is over free ( used-after-free) when I saw the crashes when calling AudioComponentInstanceDispose. But other crash points shows opposite symptoms:

  1. AudioUnitSetProperty is only called right after the AudioUnit is created, via set_device_to_audiounit. The AudioUnit in't nullptr at then (otherwise it will hit an assertion).
  2. Crashes happen when calling AudioComponentInstanceNew
padenot commented 4 years ago

It seems that it only works on Linux now. Need to find another way to diagnose the problem...

It says that it works on OSX, doesn't it? You really need ASAN for this.

ChunMinChang commented 4 years ago

It says that it works on OSX, doesn't it?

It does work on OSX without using system APIs. The ASAN in Rust only works with x86_64-unknown-linux-gnu target for now (more detail here). However, I have no way to build the coreaudio-sys (system API crate) on x86_64-unknown-linux-gnu , even I use a fullback bindings. It shows an error: error: native frameworks are only available on macOS targets. Our code relies on CoreAudio APIs so I cannot find a way to turn on ASAN on this crate. (I also tried using ASAN on coreaudio-sys crate directly, with fullback_binding, but it didn't work.)

You really need ASAN for this.

I really hope I can use ASAN..

Do you have expereince on other tools that can help diagnosing the crash here? I've tried using Instruments but I don't know how to use them effectively.

ChunMinChang commented 4 years ago

Narrow down the problematic test. Running test_set_channel_layout_input alone is able to cause a crash when the TestAudioUnit drops and call AudioComponentInstanceDispose for its inner AudioUnit. But I don't know why. I cannot find the reason.

The unit : TestAudioUnit is assigned by if let Some(unit) = test_get_default_audiounit(Scope::Input). According the this [test](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=struct%20I32(i32)%3B%0A%0Aimpl%20I32%20%7B%0A%20%20%20%20fn%20get_inner(%26self)%20-%3E%20i32%20%7B%0A%20%20%20%20%20%20%20%20self.0%0A%20%20%20%20%7D%0A%7D%0A%0Aimpl%20Default%20for%20I32%20%7B%0A%20%20%20%20fn%20default()%20-%3E%20Self%20%7B%0A%20%20%20%20%20%20%20%20I32(100)%0A%20%20%20%20%7D%0A%7D%0A%0Aimpl%20Drop%20for%20I32%20%7B%0A%20%20%20%20fn%20drop(%26mut%20self)%20%7B%0A%20%20%20%20%20%20%20%20println!(%22Drop%20%7B%7D%20%40%20%7B%3Ap%7D%22%2C%20self.0%2C%20self)%3B%0A%20%20%20%20%7D%0A%7D%0A%0Afn%20get_i32()%20-%3E%20Option%3CI32%3E%20%7B%0A%20%20%20%20Some(I32%3A%3Adefault())%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20if%20let%20Some(x)%20%3D%20get_i32()%20%7B%0A%20%20%20%20%20%20println!(%22Get%20%7B%7D%20%40%20%7B%3Ap%7D%22%2C%20x.get_inner()%2C%20%26x)%3B%0A%20%20%7D%0A%7D%0A), the unit inside the if-block is created from test_get_default_audiounit(Scope::Input) directly, so no temporary TestAudioUnit is created and dropped.

During the whole test in test_set_channel_layout_input, the only thing being used is unit's inner AudioUnit. The AudioUnit is copied to get and set the channel layout info. And I don't see the set/get API for channel layout disposing the passed AudioUnit. So the TestAudioUnit::drop should be the only place for disposing the AudioUnit.

Another weird thing is that there are some error messages about [plugin] AddInstanceForFactory and _HALCShellDriverPlugIn:

2019-12-17 16:39:32.936172-0800 cubeb_coreaudio-fb8fa5520de9e09f[56077:155977] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x100603210> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2019-12-17 16:39:32.998767-0800 cubeb_coreaudio-fb8fa5520de9e09f[56077:155977]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2019-12-17 16:39:32.999271-0800 cubeb_coreaudio-fb8fa5520de9e09f[56077:155977]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2019-12-17 16:39:33.015360-0800 cubeb_coreaudio-fb8fa5520de9e09f[56077:155977]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine

However, these error messages also appear when running test_set_channel_layout_output and test_set_channel_layout_output_undefind. So either all the channel-layout-setting-tests(or channel-layout set/get APIs) are problematic, or these error messages are always there. Need to investigate deeper about them.

So, the next thing I would do is to check whether running test_set_channel_layout_output and test_set_channel_layout_output_undefind alone is able to cause a crash. If they are not, then we can remove the test_set_channel_layout_input. We don't set channel layout on input side in cubeb so it's ok to do that.

The things need to figure out is

  1. Does channel-layout get/set API works correctly
    • channel-layout set API will be removed in #23
  2. Does test_get_default_audiounit works correctly

Whole backtrace here

(lldb) r test_set_channel_layout_input
Process 56077 launched: '/Users/cchang/Work/cubeb/src/cubeb-coreaudio-rs/target/debug/deps/cubeb_coreaudio-fb8fa5520de9e09f' (x86_64)

running 1 test
2019-12-17 16:39:32.936172-0800 cubeb_coreaudio-fb8fa5520de9e09f[56077:155977] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x100603210> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2019-12-17 16:39:32.998767-0800 cubeb_coreaudio-fb8fa5520de9e09f[56077:155977]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2019-12-17 16:39:32.999271-0800 cubeb_coreaudio-fb8fa5520de9e09f[56077:155977]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2019-12-17 16:39:33.015360-0800 cubeb_coreaudio-fb8fa5520de9e09f[56077:155977]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
Process 56077 stopped
* thread #2, name = 'backend::tests::api::test_set_channel_layout_input', stop reason = EXC_BAD_ACCESS (code=1, address=0x2)
    frame #0: 0x0000000102c0d3aa CoreAudio`___lldb_unnamed_symbol191$$CoreAudio + 122
CoreAudio`___lldb_unnamed_symbol191$$CoreAudio:
->  0x102c0d3aa <+122>: movq   (%rdi), %rax
    0x102c0d3ad <+125>: callq  *0x8(%rax)
    0x102c0d3b0 <+128>: movq   0x318(%r15), %rax
    0x102c0d3b7 <+135>: addq   $0x40, %rbx
Target 0: (cubeb_coreaudio-fb8fa5520de9e09f) stopped.
(lldb) r test_set_channel_layout_input
There is a running process, kill it and restart?: [Y/n] n
(lldb) bt
error: need to add support for DW_TAG_base_type '()' encoded with DW_ATE = 0x7, bit_size = 0
* thread #2, name = 'backend::tests::api::test_set_channel_layout_input', stop reason = EXC_BAD_ACCESS (code=1, address=0x2)
  * frame #0: 0x0000000102c0d3aa CoreAudio`___lldb_unnamed_symbol191$$CoreAudio + 122
    frame #1: 0x0000000102d05d2c CoreAudio`___lldb_unnamed_symbol3288$$CoreAudio + 30
    frame #2: 0x00007fff4f308653 AudioToolboxCore`AudioComponentInstanceDispose + 58
    frame #3: 0x00000001000e3134 cubeb_coreaudio-fb8fa5520de9e09f`_$LT$cubeb_coreaudio..backend..tests..utils..TestAudioUnit$u20$as$u20$core..ops..drop..Drop$GT$::drop::hade0d12626f943fa(self=&0x700008035788) at utils.rs:81:12
    frame #4: 0x00000001000c7bd5 cubeb_coreaudio-fb8fa5520de9e09f`core::ptr::real_drop_in_place::h9a4495cedf5ac709((null)=&0x700008035788) at mod.rs:175
    frame #5: 0x000000010000ac7d cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_channel_layout_input::h69123317f82de5dc at api.rs:995:4
    frame #6: 0x00000001001096f1 cubeb_coreaudio-fb8fa5520de9e09f`cubeb_coreaudio::backend::tests::api::test_set_channel_layout_input::_$u7b$$u7b$closure$u7d$$u7d$::h80a84f1d5587d4da((null)=&0x7000080358c0) at api.rs:983
    frame #7: 0x00000001000c44f1 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once::hb3a5bff67965f914((null)=closure-0 {

}, (null)=<unavailable>) at function.rs:227:4
    frame #8: 0x00000001001272ae cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h62abc180af5184b6 at boxed.rs:922:8 [opt]
    frame #9: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #10: 0x0000000100140477 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panicking::try::hc6851a78b7283b60 at panicking.rs:271:12 [opt]
    frame #11: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b [inlined] std::panic::catch_unwind::h4f224793963be037 at panic.rs:394 [opt]
    frame #12: 0x0000000100140432 cubeb_coreaudio-fb8fa5520de9e09f`test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h26163299dd66a05b at lib.rs:1413 [opt]
    frame #13: 0x000000010011c915 cubeb_coreaudio-fb8fa5520de9e09f`std::sys_common::backtrace::__rust_begin_short_backtrace::h09f30e53b0d36855 at backtrace.rs:126:4 [opt]
    frame #14: 0x0000000100120ad5 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h11ad033de2bf23bd at mod.rs:470:16 [opt]
    frame #15: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 [inlined] _$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::hdfd84f2d534f6c68 at panic.rs:315 [opt]
    frame #16: 0x0000000100120ac2 cubeb_coreaudio-fb8fa5520de9e09f`std::panicking::try::do_call::h2a1d2c5cb64914d2 at panicking.rs:292 [opt]
    frame #17: 0x000000010018050f cubeb_coreaudio-fb8fa5520de9e09f`__rust_maybe_catch_panic at lib.rs:80:7 [opt]
    frame #18: 0x0000000100121085 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panicking::try::h830b2026ed6a44c3 at panicking.rs:271:12 [opt]
    frame #19: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::panic::catch_unwind::h8489ab8e1eca8899 at panic.rs:394 [opt]
    frame #20: 0x000000010012104c cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::hb9ab1346bf0aa0ce at mod.rs:469 [opt]
    frame #21: 0x0000000100121017 cubeb_coreaudio-fb8fa5520de9e09f`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h8de107699c84b337 at function.rs:227 [opt]
    frame #22: 0x0000000100173c7e cubeb_coreaudio-fb8fa5520de9e09f`_$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd1afe4d791e3679f at boxed.rs:922:8 [opt]
    frame #23: 0x000000010017fd9e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] _$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::hd175b6857cf77782 at boxed.rs:922:8 [opt]
    frame #24: 0x000000010017fd92 cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 [inlined] std::sys_common::thread::start_thread::hed1d18da7acfc5a9 at thread.rs:13 [opt]
    frame #25: 0x000000010017fd1e cubeb_coreaudio-fb8fa5520de9e09f`std::sys::unix::thread::Thread::new::thread_start::h785fcf8d81bd0f52 at thread.rs:79 [opt]
    frame #26: 0x00007fff724cee65 libsystem_pthread.dylib`_pthread_start + 148
    frame #27: 0x00007fff724ca83b libsystem_pthread.dylib`thread_start + 15
(lldb) 
ChunMinChang commented 4 years ago

I've check that running test_set_channel_layout_output and test_set_channel_layout_output_undefind is fine. And the calling audiounit_get_current_channel_layout(x) is prone to cause the intermittent crash, where x is a input-only (microphone-only) AudioUnit. (However, calling audiounit_set_channel_layout(x) is fine.)

I'll file a PR to fix this

padenot commented 4 years ago

I had a go at this:

rustup install nightly-2019-09-10

has sanitizers working, and it works when compiling this crate, you can activate it via:

rustup default nightly-2019-09-11

This allows side-stepping https://github.com/rust-lang/rust/issues/66140. Then we need to remove the staticlib in crate-type in the top-level Cargo.toml, and then it compiles.

Hopefully we can find the cause with this. We can disable the test (I'll review the patch that does that next), but it's best to understand the crash here anyways.

ChunMinChang commented 4 years ago

I had a go at this:

Great thanks!

After running

rustup default nightly-2019-09-11

and remove staticlib in top-level Cargo.toml, now I can run ASAN by RUSTFLAGS="-Z sanitizer=address" cargo test

I was misled by the document here. It says ASAN only works on x86_64-unknown-linux-gnu.

I'll check what I could find. Thanks!

ChunMinChang commented 4 years ago

I cannot reproduce it by RUSTFLAGS="-Z sanitizer=address" cargo test with nightly-2019-09-11. But there is a data race issue found when running RUSTFLAGS="-Z sanitizer=thread" cargo test. I've open #34 for it.

ChunMinChang commented 4 years ago

Record the last commit that can lead to this crash: https://github.com/ChunMinChang/cubeb-coreaudio-rs/tree/9d0a0e8f635f2a630b17562b53f46efed0e3e91f