the event loop may deadlock because it drops Arc<LinuxDevice>
s while DEVICES
is locked. Dropping a LinuxDevice
will unregister its fd, which locks DEVICES
reentrantly.
problem seen in the wild, backtrace from gdb:
#0 syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#1 0x0000562ffff02214 in std::sys::unix::futex::futex_wait () at library/std/src/sys/unix/futex.rs:62
#2 std::sys::unix::locks::futex_mutex::Mutex::lock_contended () at library/std/src/sys/unix/locks/futex_mutex.rs:56
#3 0x0000562fffb3cc2d in std::sys::unix::locks::futex_mutex::Mutex::lock (self=<optimized out>)
at /rustc/e0d7ed1f453fb54578cc96dfea859b0e7be15016/library/std/src/sys/unix/locks/futex_mutex.rs:28
#4 std::sync::mutex::Mutex<slab::Slab<alloc::sync::Weak<nusb::platform::linux_usbfs::device::LinuxDevice, alloc::alloc::Global>>>::lock<slab::Slab<alloc::sync::Weak<nusb::platform::linux_usbfs::device::LinuxDevice, alloc::alloc::Global>>> (self=<optimized out>)
at /rustc/e0d7ed1f453fb54578cc96dfea859b0e7be15016/library/std/src/sync/mutex.rs:273
#5 nusb::platform::linux_usbfs::events::unregister (fd=<optimized out>, events_id=0) at src/platform/linux_usbfs/events.rs:48
#6 0x0000562fffb3a245 in nusb::platform::linux_usbfs::device::{impl#1}::drop (self=<optimized out>)
at src/platform/linux_usbfs/device.rs:116
#7 core::ptr::drop_in_place<nusb::platform::linux_usbfs::device::LinuxDevice> ()
at /rustc/e0d7ed1f453fb54578cc96dfea859b0e7be15016/library/core/src/ptr/mod.rs:497
#8 alloc::sync::Arc<nusb::platform::linux_usbfs::device::LinuxDevice, alloc::alloc::Global>::drop_slow<nusb::platform::linux_usbfs::device::LinuxDevice, alloc::alloc::Global> (self=<optimized out>)
at /rustc/e0d7ed1f453fb54578cc96dfea859b0e7be15016/library/alloc/src/sync.rs:1751
#9 0x0000562fffb3cf29 in alloc::sync::{impl#33}::drop<nusb::platform::linux_usbfs::device::LinuxDevice, alloc::alloc::Global> (
self=0x7fad8f800b28) at /rustc/e0d7ed1f453fb54578cc96dfea859b0e7be15016/library/alloc/src/sync.rs:2407
#10 core::ptr::drop_in_place<alloc::sync::Arc<nusb::platform::linux_usbfs::device::LinuxDevice, alloc::alloc::Global>> ()
at /rustc/e0d7ed1f453fb54578cc96dfea859b0e7be15016/library/core/src/ptr/mod.rs:497
#11 nusb::platform::linux_usbfs::events::event_loop () at src/platform/linux_usbfs/events.rs:63
#12 0x0000562fffb3bdc6 in core::ops::function::FnOnce::call_once<fn(), ()> ()
at /rustc/e0d7ed1f453fb54578cc96dfea859b0e7be15016/library/core/src/ops/function.rs:250
#13 std::sys_common::backtrace::__rust_begin_short_backtrace<fn(), ()> (f=<optimized out>)
at /rustc/e0d7ed1f453fb54578cc96dfea859b0e7be15016/library/std/src/sys_common/backtrace.rs:154
#14 0x0000562fffb392e1 in std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure#0}<fn(), ()> ()
at /rustc/e0d7ed1f453fb54578cc96dfea859b0e7be15016/library/std/src/thread/mod.rs:529