deviceplug / btleplug

Rust Cross-Platform Host-Side Bluetooth LE Access Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OSx When a device disappears and you try to connect > Event receiver died

Rust-Trends opened this issue · comments

Hi,

System: macOS 12.6
btleplug = "0.10.1"

Working with btleplug scanning devices and connecting to write a characteristic works correctly. Only when I turn off the device, the device is still present in the peripherals list kept by the Manager. When it tries to connect I get the following:

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/btleplug-0.10.1/src/corebluetooth/internal.rs:238:14
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142:14
   2: core::panicking::panic
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:48:5
   3: core::option::Option<T>::unwrap
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/option.rs:775:21
   4: btleplug::corebluetooth::internal::CBPeripheral::confirm_disconnect
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/btleplug-0.10.1/src/corebluetooth/internal.rs:236:9
   5: btleplug::corebluetooth::internal::CoreBluetoothInternal::on_peripheral_disconnect::{{closure}}
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/btleplug-0.10.1/src/corebluetooth/internal.rs:506:13
   6: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/mod.rs:91:19
   7: btleplug::corebluetooth::internal::CoreBluetoothInternal::wait_for_message::{{closure}}
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/btleplug-0.10.1/src/corebluetooth/internal.rs:774:71
   8: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/mod.rs:91:19
   9: btleplug::corebluetooth::internal::run_corebluetooth_thread::{{closure}}::{{closure}}
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/btleplug-0.10.1/src/corebluetooth/internal.rs:909:39
  10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/mod.rs:91:19
  11: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/future.rs:124:9
  12: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/runtime/scheduler/current_thread.rs:525:48
  13: tokio::coop::with_budget::{{closure}}
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/coop.rs:102:9
  14: std::thread::local::LocalKey<T>::try_with
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/thread/local.rs:445:16
  15: std::thread::local::LocalKey<T>::with
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/thread/local.rs:421:9
  16: tokio::coop::with_budget
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/coop.rs:95:5
  17: tokio::coop::budget
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/coop.rs:72:5
  18: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/runtime/scheduler/current_thread.rs:525:25
  19: tokio::runtime::scheduler::current_thread::Context::enter
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/runtime/scheduler/current_thread.rs:349:19
  20: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/runtime/scheduler/current_thread.rs:524:36
  21: tokio::runtime::scheduler::current_thread::CoreGuard::enter::{{closure}}
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/runtime/scheduler/current_thread.rs:595:57
  22: tokio::macros::scoped_tls::ScopedKey<T>::set
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/macros/scoped_tls.rs:61:9
  23: tokio::runtime::scheduler::current_thread::CoreGuard::enter
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/runtime/scheduler/current_thread.rs:595:27
  24: tokio::runtime::scheduler::current_thread::CoreGuard::block_on
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/runtime/scheduler/current_thread.rs:515:19
  25: tokio::runtime::scheduler::current_thread::CurrentThread::block_on
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/runtime/scheduler/current_thread.rs:161:24
  26: tokio::runtime::Runtime::block_on
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.1/src/runtime/mod.rs:490:46
  27: btleplug::corebluetooth::internal::run_corebluetooth_thread::{{closure}}
             at /Users/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/btleplug-0.10.1/src/corebluetooth/internal.rs:906:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.
 ERROR btleplug::corebluetooth::peripheral > Event receiver died, breaking out of corebluetooth device loop.

The unwrap it is referring to is :

pub fn confirm_disconnect(&mut self) {
        self.disconnected_future_state
            .take()
-->       .unwrap()
            .lock()
            .unwrap()
            .set_reply(CoreBluetoothReply::Ok);
    }

Thanks
Bob
Rust-Trends.com

commented

Fixed as part of #274