Open parasyte opened 1 month ago
This application nests the winit event loop inside the tokio event loop: https://github.com/ChrisRega/example-blog-client/blob/7b42b9aef9820f5a66f8680854046cc7835a8bd5/src/main.rs#L17-L26
winit
tokio
Doing this is undefined behavior. It causes serious problems on platforms like macOS, and blocks one of the tokio worker threads. This flavor of UB is visible on macOS where the app will crash with an uncaught exception when closing the window:
Further reading:
Thanks for the report!
This application nests the
winit
event loop inside thetokio
event loop: https://github.com/ChrisRega/example-blog-client/blob/7b42b9aef9820f5a66f8680854046cc7835a8bd5/src/main.rs#L17-L26Doing this is undefined behavior. It causes serious problems on platforms like macOS, and blocks one of the
tokio
worker threads. This flavor of UB is visible on macOS where the app will crash with an uncaught exception when closing the window:Trace/BPT trap: 5
``` Process: example_blog_client [88174] Path: /Users/USER/*/example_blog_client Identifier: example_blog_client Version: ??? Code Type: ARM-64 (Native) Parent Process: bash [21143] Responsible: Terminal [7005] User ID: 501 Date/Time: 2024-10-23 07:32:37.4558 -0700 OS Version: macOS 14.6.1 (23G93) Report Version: 12 Anonymous UUID: CFCF464F-AF6C-A205-19C6-73C7EBE19B5C Sleep/Wake UUID: F6360395-3827-4373-A55D-758348322FE5 Time Awake Since Boot: 1000000 seconds Time Since Wake: 329 seconds System Integrity Protection: enabled Crashed Thread: 0 main Dispatch queue: com.apple.main-thread Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x000000018e10f758 Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5 Terminating Process: exc handler [88174] Application Specific Backtrace 0: 0 CoreFoundation 0x000000018a64a2ec __exceptionPreprocess + 176 1 libobjc.A.dylib 0x000000018a12e158 objc_exception_throw + 60 2 Foundation 0x000000018b6fc36c -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 628 3 Foundation 0x000000018b6fc0a4 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 136 4 Foundation 0x000000018b6fbd70 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 196 5 AppKit 0x000000018e5393e4 -[_NSTouchBarFinderObservation invalidate] + 264 6 AppKit 0x000000018e53a738 ___NSTouchBarFinderSetNeedsUpdateOnMain_block_invoke_2 + 628 7 AppKit 0x000000018ded7cec NSDisplayCycleObserverInvoke + 168 8 AppKit 0x000000018ded7948 NSDisplayCycleFlush + 644 9 QuartzCore 0x00000001927ca98c _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 120 10 QuartzCore 0x00000001927c972c _ZN2CA11Transaction6commitEv + 320 11 AppKit 0x000000018df5bac8 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 272 12 AppKit 0x000000018e91c4e4 ___NSRunLoopObserverCreateWithHandler_block_invoke + 64 13 CoreFoundation 0x000000018a5d487c __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36 14 CoreFoundation 0x000000018a5d4768 __CFRunLoopDoObservers + 536 15 CoreFoundation 0x000000018a5d3d94 __CFRunLoopRun + 776 16 CoreFoundation 0x000000018a5d3434 CFRunLoopRunSpecific + 608 17 HIToolbox 0x0000000194d7d19c RunCurrentEventLoopInMode + 292 18 HIToolbox 0x0000000194d7ce2c ReceiveNextEventCommon + 220 19 HIToolbox 0x0000000194d7cd30 _BlockUntilNextEventMatchingListInModeWithFilter + 76 20 AppKit 0x000000018de32cc8 _DPSNextEvent + 660 21 AppKit 0x000000018e6294d0 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 700 22 AppKit 0x000000018de25ffc -[NSApplication run] + 476 23 example_blog_client 0x000000010216cc60 _ZN5winit13platform_impl8platform10event_loop18EventLoop$LT$T$GT$10run_return17hd204e57310b01024E + 380 24 example_blog_client 0x000000010217ae00 _ZN6eframe6native3run14run_and_return17h98b04053861a1c38E + 572 25 example_blog_client 0x000000010216b268 _ZN6eframe6native3run16glow_integration8run_glow17h73e6eff3e463615aE + 596 26 example_blog_client 0x000000010217b29c _ZN6eframe10run_native17hf2ac08c50c3f68a8E + 428 27 example_blog_client 0x0000000102075a14 _ZN5tokio7runtime4park16CachedParkThread8block_on17hfbfd26e6bada6b29E + 224 28 example_blog_client 0x00000001020796e4 _ZN5tokio7runtime7runtime7Runtime8block_on17h6ea9cf69a2a8ee76E + 88 29 example_blog_client 0x0000000102052dbc _ZN19example_blog_client4main17h0eddff21d4633986E + 112 30 example_blog_client 0x0000000102077ba4 _ZN3std3sys9backtrace28__rust_begin_short_backtrace17h1f48f483b07c3691E + 12 31 example_blog_client 0x0000000102074398 _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h9a6c470f04bee322E.llvm.18315569416295985373 + 16 32 example_blog_client 0x00000001023bbdc0 _ZN3std2rt19lang_start_internal17h738180e634528c71E + 812 33 example_blog_client 0x0000000102052e7c main + 52 34 dyld 0x000000018a16b154 start + 2476 Thread 0 Crashed:: main Dispatch queue: com.apple.main-thread 0 AppKit 0x18e10f758 -[NSApplication _crashOnException:] + 240 1 AppKit 0x18df5bc3c __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 644 2 AppKit 0x18e91c4e4 ___NSRunLoopObserverCreateWithHandler_block_invoke + 64 3 CoreFoundation 0x18a5d487c __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36 4 CoreFoundation 0x18a5d4768 __CFRunLoopDoObservers + 536 5 CoreFoundation 0x18a5d3d94 __CFRunLoopRun + 776 6 CoreFoundation 0x18a5d3434 CFRunLoopRunSpecific + 608 7 HIToolbox 0x194d7d19c RunCurrentEventLoopInMode + 292 8 HIToolbox 0x194d7ce2c ReceiveNextEventCommon + 220 9 HIToolbox 0x194d7cd30 _BlockUntilNextEventMatchingListInModeWithFilter + 76 10 AppKit 0x18de32cc8 _DPSNextEvent + 660 11 AppKit 0x18e6294d0 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 700 12 AppKit 0x18de25ffc -[NSApplication run] + 476 13 example_blog_client 0x10216cc60 winit::platform_impl::platform::event_loop::EventLoop$LT$T$GT$::run_return::hd204e57310b01024 + 380 14 example_blog_client 0x10217ae00 eframe::native::run::run_and_return::h98b04053861a1c38 + 572 15 example_blog_client 0x10216b268 eframe::native::run::glow_integration::run_glow::h73e6eff3e463615a + 596 16 example_blog_client 0x10217b29c eframe::run_native::hf2ac08c50c3f68a8 + 428 17 example_blog_client 0x102075a14 tokio::runtime::park::CachedParkThread::block_on::hfbfd26e6bada6b29 + 224 18 example_blog_client 0x1020796e4 tokio::runtime::runtime::Runtime::block_on::h6ea9cf69a2a8ee76 + 88 19 example_blog_client 0x102052dbc example_blog_client::main::h0eddff21d4633986 + 112 20 example_blog_client 0x102077ba4 std::sys::backtrace::__rust_begin_short_backtrace::h1f48f483b07c3691 + 12 21 example_blog_client 0x102074398 std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h9a6c470f04bee322 (.llvm.18315569416295985373) + 16 22 example_blog_client 0x1023bbdc0 std::rt::lang_start_internal::h738180e634528c71 + 812 23 example_blog_client 0x102052e7c main + 52 24 dyld 0x18a16b154 start + 2476 Thread 1:: tokio-runtime-worker 0 libsystem_kernel.dylib 0x18a4baf40 kevent + 8 1 example_blog_client 0x1023a2b1c mio::poll::Poll::poll::h2e4310d4ea0fbade + 116 2 example_blog_client 0x10238fe98 tokio::runtime::io::Driver::turn::hf0008c1ab73a6f72 (.llvm.16663742601449969147) + 88 3 example_blog_client 0x102390660 tokio::runtime::time::Driver::park_internal::hd799af5bbfe1604b (.llvm.16663742601449969147) + 688 4 example_blog_client 0x10238aa80 tokio::runtime::scheduler::multi_thread::park::Parker::park::hd1c8149a5a640831 + 440 5 example_blog_client 0x1023853d4 tokio::runtime::scheduler::multi_thread::worker::Context::park_timeout::hd9d677c8cbb051cc + 152 6 example_blog_client 0x102384c58 tokio::runtime::scheduler::multi_thread::worker::Context::run::h67dd108fa651a15a + 1260 7 example_blog_client 0x1023962b8 tokio::macros::scoped_tls::ScopedKey$LT$T$GT$::set::hc5fbf11fa4d71847 + 84 8 example_blog_client 0x102384668 tokio::runtime::scheduler::multi_thread::worker::run::h17700621f5c59ec3 + 132 9 example_blog_client 0x10238595c _$LT$tokio..runtime..blocking..task..BlockingTask$LT$T$GT$$u20$as$u20$core..future..future..Future$GT$::poll::h7ef90a31b5cc97ca + 80 10 example_blog_client 0x10239a6c4 tokio::runtime::task::core::Core$LT$T$C$S$GT$::poll::h6b1ea7dfeb277b85 + 148 11 example_blog_client 0x1023913c4 tokio::runtime::task::harness::Harness$LT$T$C$S$GT$::poll::h36aa34a38b3efdb2 + 176 12 example_blog_client 0x10238bf70 tokio::runtime::blocking::pool::Inner::run::h2cb318c4b884e453 + 408 13 example_blog_client 0x10238108c std::sys::backtrace::__rust_begin_short_backtrace::hd9606544b2d39132 + 80 14 example_blog_client 0x102399284 core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h886c10b4a08115c0 + 188 15 example_blog_client 0x1023c5214 std::sys::pal::unix::thread::Thread::new::thread_start::h7f24d7d921e6556e + 52 16 libsystem_pthread.dylib 0x18a4f5f94 _pthread_start + 136 17 libsystem_pthread.dylib 0x18a4f0d34 thread_start + 8 Thread 2: 0 libsystem_pthread.dylib 0x18a4f0d20 start_wqthread + 0 Thread 3: 0 libsystem_pthread.dylib 0x18a4f0d20 start_wqthread + 0 Thread 4: 0 libsystem_pthread.dylib 0x18a4f0d20 start_wqthread + 0 Thread 5: 0 libsystem_pthread.dylib 0x18a4f0d20 start_wqthread + 0 Thread 6:: tokio-runtime-worker 0 libsystem_kernel.dylib 0x18a4b85ec __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18a4f655c _pthread_cond_wait + 1228 2 example_blog_client 0x1023c5c04 std::sys::sync::condvar::pthread::Condvar::wait_timeout::h9c14fc6b89193d63 + 256 3 example_blog_client 0x10238bea8 tokio::runtime::blocking::pool::Inner::run::h2cb318c4b884e453 + 208 4 example_blog_client 0x10238108c std::sys::backtrace::__rust_begin_short_backtrace::hd9606544b2d39132 + 80 5 example_blog_client 0x102399284 core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h886c10b4a08115c0 + 188 6 example_blog_client 0x1023c5214 std::sys::pal::unix::thread::Thread::new::thread_start::h7f24d7d921e6556e + 52 7 libsystem_pthread.dylib 0x18a4f5f94 _pthread_start + 136 8 libsystem_pthread.dylib 0x18a4f0d34 thread_start + 8 Thread 7:: tokio-runtime-worker 0 libsystem_kernel.dylib 0x18a4b85ec __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x18a4f655c _pthread_cond_wait + 1228 2 example_blog_client 0x1023c5c04 std::sys::sync::condvar::pthread::Condvar::wait_timeout::h9c14fc6b89193d63 + 256 3 example_blog_client 0x10238bea8 tokio::runtime::blocking::pool::Inner::run::h2cb318c4b884e453 + 208 4 example_blog_client 0x10238108c std::sys::backtrace::__rust_begin_short_backtrace::hd9606544b2d39132 + 80 5 example_blog_client 0x102399284 core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h886c10b4a08115c0 + 188 6 example_blog_client 0x1023c5214 std::sys::pal::unix::thread::Thread::new::thread_start::h7f24d7d921e6556e + 52 7 libsystem_pthread.dylib 0x18a4f5f94 _pthread_start + 136 8 libsystem_pthread.dylib 0x18a4f0d34 thread_start + 8 Thread 8:: com.apple.NSEventThread 0 libsystem_kernel.dylib 0x18a4b4df4 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x18a4c75e4 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x18a4bd9c4 mach_msg_overwrite + 476 3 libsystem_kernel.dylib 0x18a4b5178 mach_msg + 24 4 CoreFoundation 0x18a5d5680 __CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x18a5d3f44 __CFRunLoopRun + 1208 6 CoreFoundation 0x18a5d3434 CFRunLoopRunSpecific + 608 7 AppKit 0x18df5d280 _NSEventThread + 144 8 libsystem_pthread.dylib 0x18a4f5f94 _pthread_start + 136 9 libsystem_pthread.dylib 0x18a4f0d34 thread_start + 8 Thread 0 crashed with ARM Thread State (64-bit): x0: 0x000000013f945400 x1: 0x000000013f94ad39 x2: 0xfffffffffffffff8 x3: 0x000000013f946318 x4: 0x0000000000004a01 x5: 0x0000000000000020 x6: 0x000000013f945400 x7: 0x0000000000000f58 x8: 0x00000001f28a5000 x9: 0x8ba4586afe9700d6 x10: 0x8ba4586afe9700d6 x11: 0x000000000000007f x12: 0x0000000000000017 x13: 0x000000013f926960 x14: 0x01000001f235c589 x15: 0x00000001f235c588 x16: 0x000000018a5261a0 x17: 0x00000001fca42aa8 x18: 0x0000000000000000 x19: 0x00006000031452f0 x20: 0x0000600002a09540 x21: 0x0000168d57ab2854 x22: 0x000000013f009050 x23: 0x000000016ddbfec0 x24: 0x0000000000000000 x25: 0x0000000000000000 x26: 0x0000600000e1d360 x27: 0x0000600003144f00 x28: 0x000000018a5d4e04 fp: 0x000000016ddbfd30 lr: 0x102e80018e10f750 sp: 0x000000016ddbfd00 pc: 0x000000018e10f758 cpsr: 0x60001000 far: 0x0000000000000000 esr: 0xf2000001 (Breakpoint) brk 1 Binary Images: 0x10cfd4000 - 0x10cfdffff libobjc-trampolines.dylib (*) <7d6ca1cb-c5e6-38b6-9618-2c580486fc6b> /usr/lib/libobjc-trampolines.dylib 0x102da0000 - 0x102e0bfff com.apple.AppleMetalOpenGLRenderer (1.0)Further reading: