ewilken / hap-rs

Rust implementation of the Apple HomeKit Accessory Protocol (HAP)
Apache License 2.0
197 stars 35 forks source link

thread 'main' panicked at 'couldn't send event response: ()' #9

Closed insitusec closed 6 years ago

insitusec commented 6 years ago

This seems to happen in response to an accessory being removed and re-added.

reproduce

  1. Add Outlet accessory (paired successfully)
  2. Remove Outlet accessory
  3. Re-add same Outlet accessory (paired successfully)
  4. Return to Home app accessory list
  5. Panic

test code

(mostly taken straight out of the hap-rs docs)

extern crate hap;
extern crate failure;

use failure::Error;

use hap::{
    transport::{Transport, IpTransport},
    accessory::{Category, Information, outlet},
    characteristic::{Readable, Updatable},
    Config,
    HapType,
};

#[derive(Debug, Clone)]
pub struct VirtualOutlet {
    on: bool,
}

impl Readable<bool> for VirtualOutlet {
    fn on_read(&mut self, _: HapType) -> Option<bool> {
        println!("On read.");
        Some(self.on)
    }
}

impl Updatable<bool> for VirtualOutlet {
    fn on_update(&mut self, old_val: &bool, new_val: &bool, _: HapType) {
        println!("On updated from {} to {}.", old_val, new_val);
        if new_val != old_val { self.on = new_val.clone(); }
    }
}

fn main() -> Result<(), Error> {
    let info = Information {
        name: "Outlet".into(),
        ..Default::default()
    };

    let mut outlet = outlet::new(info).unwrap();

    let virtual_outlet = VirtualOutlet { on: false };
    outlet.inner.outlet.inner.on.set_readable(virtual_outlet.clone()).unwrap();
    outlet.inner.outlet.inner.on.set_updatable(virtual_outlet).unwrap();

    let config = Config {
        name: "Outlet".into(),
        category: Category::Outlet,
        ..Default::default()
    };

    let mut ip_transport = IpTransport::new(config).unwrap();
    ip_transport.add_accessory(outlet).unwrap();
    ip_transport.start().unwrap();

    Ok(())
}

backtrace

$ RUST_BACKTRACE=1 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.25s
     Running `target/debug/hap-fun`
On read.
On updated from false to false.
On updated from false to true.
On updated from true to false.
On updated from false to true.
On read.
On updated from true to false.
On read.
On updated from false to false.
On updated from false to true.
thread 'main' panicked at 'couldn't send event response: ()', libcore/result.rs:945:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get
             at libstd/panicking.rs:511
   5: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:426
   6: std::panicking::try::do_call
             at libstd/panicking.rs:337
   7: <T as core::any::Any>::get_type_id
             at libcore/panicking.rs:92
   8: tokio_threadpool::worker::entry::WorkerEntry::set_next_sleeper
             at /Users/travis/build/rust-lang/rust/src/libcore/macros.rs:26
   9: std::thread::panicking
             at /Users/travis/build/rust-lang/rust/src/libcore/result.rs:809
  10: hap::transport::http::server::serve::{{closure}}::{{closure}}
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/transport/http/server.rs:224
  11: hap::pin::new
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/event.rs:26
  12: core::alloc::Layout::align
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/characteristic/mod.rs:150
  13: core::alloc::Layout::align
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/characteristic/mod.rs:364
  14: hap::db::accessory_list::AccessoryList::write_characteristic
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/db/accessory_list.rs:162
  15: hap::transport::http::handlers::characteristics::UpdateCharacteristics::new
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/transport/http/handlers/characteristics.rs:151
  16: hap::transport::http::server::serve::{{closure}}
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/transport/http/handlers/mod.rs:112
  17: <hap::transport::http::server::Api as tokio_service::Service>::call::{{closure}}
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/transport/http/server.rs:163
  18: <hap::characteristic::Format as core::cmp::PartialEq>::eq
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/and_then.rs:34
  19: std::thread::panicking
             at /Users/travis/build/rust-lang/rust/src/libcore/result.rs:468
  20: <hap::characteristic::Format as core::cmp::PartialEq>::eq
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/and_then.rs:33
  21: <hyper::method::Method as core::clone::Clone>::clone
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/chain.rs:39
  22: <hap::characteristic::Format as core::cmp::PartialEq>::eq
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/and_then.rs:32
  23: <core::cmp::Ordering as core::cmp::PartialEq>::eq
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/mod.rs:113
  24: <hap::db::accessory_list::AccessoryList as core::clone::Clone>::clone
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.11.27/src/proto/h1/dispatch.rs:343
  25: <hyper::header::raw::RawLines<'a> as core::iter::iterator::Iterator>::next
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.11.27/src/proto/h1/dispatch.rs:230
  26: <hyper::header::raw::RawLines<'a> as core::iter::iterator::Iterator>::next
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.11.27/src/proto/h1/dispatch.rs:97
  27: <hyper::header::raw::RawLines<'a> as core::iter::iterator::Iterator>::next
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.11.27/src/proto/h1/dispatch.rs:85
  28: <hyper::header::raw::RawLines<'a> as core::iter::iterator::Iterator>::next
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.11.27/src/proto/h1/dispatch.rs:73
  29: <hap::db::accessory_list::AccessoryList as core::clone::Clone>::clone
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.11.27/src/proto/h1/dispatch.rs:316
  30: futures::task_impl::core::get_ptr
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.11.27/src/server/conn.rs:112
  31: <hyper::header::raw::RawLines<'a> as core::iter::iterator::Iterator>::next
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/map_err.rs:30
  32: futures::task_impl::core::get_ptr
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/map.rs:30
  33: <std::time::Instant as core::cmp::PartialOrd>::gt
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/future/mod.rs:113
  34: tokio_current_thread::CURRENT::__init
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/mod.rs:289
  35: tokio_current_thread::CURRENT::__init
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/mod.rs:363
  36: futures::task_impl::std::BorrowedUnpark::new
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/std/mod.rs:78
  37: tokio_current_thread::CURRENT::__init
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/mod.rs:363
  38: tokio_current_thread::CURRENT::__init
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.23/src/task_impl/mod.rs:289
  39: <core::cell::BorrowRefMut<'b> as core::ops::drop::Drop>::drop
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-current-thread-0.1.1/src/scheduler.rs:353
  40: <core::cell::BorrowRefMut<'b> as core::ops::drop::Drop>::drop
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-current-thread-0.1.1/src/scheduler.rs:332
  41: core::sync::atomic::fence
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-current-thread-0.1.1/src/lib.rs:747
  42: tokio_core::reactor::CURRENT_LOOP::FOO::__getit
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-current-thread-0.1.1/src/lib.rs:783
  43: core::sync::atomic::fence
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-current-thread-0.1.1/src/lib.rs:746
  44: futures::task_impl::core::get_ptr
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:294
  45: futures::task_impl::core::get_ptr
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:248
  46: core::sync::atomic::fence
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-current-thread-0.1.1/src/lib.rs:745
  47: <core::cell::BorrowRefMut<'b> as core::ops::drop::Drop>::drop
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-current-thread-0.1.1/src/scheduler.rs:332
  48: core::sync::atomic::fence
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-current-thread-0.1.1/src/lib.rs:591
  49: core::sync::atomic::fence
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-current-thread-0.1.1/src/lib.rs:517
  50: tokio_core::reactor::Core::poll::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:298
  51: <libmdns::dns_parser::enums::QueryClass as core::cmp::PartialEq>::eq
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-0.1.2/src/lib.rs:155
  52: tokio_core::reactor::Core::poll::{{closure}}::{{closure}}::{{closure}}
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:297
  53: tokio_core::net::udp::UdpSocket::poll_read::{{closure}}
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.6/src/timer/handle.rs:94
  54: futures::task_impl::core::get_ptr
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:294
  55: futures::task_impl::core::get_ptr
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:248
  56: tokio_core::net::udp::UdpSocket::poll_read::{{closure}}
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.6/src/timer/handle.rs:81
  57: tokio_core::reactor::Core::poll::{{closure}}::{{closure}}
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:275
  58: core::num::<impl usize>::overflowing_add
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.4/src/global.rs:173
  59: futures::task_impl::core::get_ptr
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:294
  60: futures::task_impl::core::get_ptr
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:248
  61: core::num::<impl usize>::overflowing_add
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.4/src/global.rs:143
  62: tokio_core::reactor::Core::poll::{{closure}}
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:274
  63: tokio_timer::timer::handle::CURRENT_TIMER::__init
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.5/src/lib.rs:232
  64: futures::task_impl::core::get_ptr
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:294
  65: futures::task_impl::core::get_ptr
             at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:248
  66: tokio_timer::timer::handle::CURRENT_TIMER::__init
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.5/src/lib.rs:215
  67: <core::cmp::Ordering as core::cmp::PartialEq>::eq
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:273
  68: <alloc::vec::SetLenOnDrop<'a> as core::ops::drop::Drop>::drop
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:248
  69: hap::transport::http::server::serve
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/transport/http/server.rs:238
  70: hap::transport::http::handlers::characteristics::UpdateCharacteristics::new
             at /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/hap-0.0.2/src/transport/ip.rs:150
  71: hap_fun::main
             at src/main.rs:55
  72: std::rt::lang_start::{{closure}}
             at /Users/travis/build/rust-lang/rust/src/libstd/rt.rs:74
  73: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  74: panic_unwind::dwarf::eh::read_encoded_pointer
             at libpanic_unwind/lib.rs:105
  75: std::sys_common::at_exit_imp::push
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  76: std::rt::lang_start
             at /Users/travis/build/rust-lang/rust/src/libstd/rt.rs:74
  77: <hap_fun::VirtualOutlet as core::clone::Clone>::clone
ewilken commented 6 years ago

v0.0.3 with a fix will be released today. Thanks a lot for reporting this and sorry for the delay!