Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

ThreadedSocketService panics while accepting connection #300

Closed
wikylyu opened this issue Jun 2, 2020 · 4 comments · Fixed by #301
Closed

ThreadedSocketService panics while accepting connection #300

wikylyu opened this issue Jun 2, 2020 · 4 comments · Fixed by #301

Comments

@wikylyu
Copy link

wikylyu commented Jun 2, 2020

I'm learning to use gio. And below is my code

use glib::MainContext;
use glib::MainLoop;
use gio::ThreadedSocketService;
use gio::prelude::*;

fn main() {
    let mainloop = MainLoop::new(Some(&MainContext::default()),false);

    let service  = ThreadedSocketService::new(-1);

    if let Err(err) = service.add_inet_port::<glib::Object>(32321, None) {
        return;
    }
    println!("listen 32321");

    service.connect_run(move |_,c,_|->bool{
        println!("{:?}",c);
        return false;
    });

    mainloop.run();
}

When ThreadedSocketService receives a connection, it panics.

   Compiling gtk v0.1.0 (/home/wiky/temp/rust/gtk)
warning: unused variable: `err`
  --> src/main.rs:11:16
   |
11 |     if let Err(err) = service.add_inet_port::<glib::Object>(32321, None) {
   |                ^^^ help: consider prefixing with an underscore: `_err`
   |
   = note: `#[warn(unused_variables)]` on by default

    Finished dev [unoptimized + debuginfo] target(s) in 1.67s
     Running `target/debug/gtk`
listen 32321

connection established

thread '<unnamed>' panicked at 'assertion failed: crate::types::instance_of::<Self>(ptr as *const _)', <::std::macros::panic macros>:2:4
stack backtrace:
   0:     0x55d6a79929f4 - backtrace::backtrace::libunwind::trace::h5d52ba5f20882f09
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1:     0x55d6a79929f4 - backtrace::backtrace::trace_unsynchronized::hceee092869668a74
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
   2:     0x55d6a79929f4 - std::sys_common::backtrace::_print_fmt::ha312c2904605e4d5
                               at src/libstd/sys_common/backtrace.rs:78
   3:     0x55d6a79929f4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5b9981092140b727
                               at src/libstd/sys_common/backtrace.rs:59
   4:     0x55d6a79ab7fc - core::fmt::write::h5f6d7d8de88b4173
                               at src/libcore/fmt/mod.rs:1063
   5:     0x55d6a7990f33 - std::io::Write::write_fmt::h893169117de3cc15
                               at src/libstd/io/mod.rs:1426
   6:     0x55d6a7994fa5 - std::sys_common::backtrace::_print::h8ab61d4120f7a335
                               at src/libstd/sys_common/backtrace.rs:62
   7:     0x55d6a7994fa5 - std::sys_common::backtrace::print::h8aae19fbb153bf2a
                               at src/libstd/sys_common/backtrace.rs:49
   8:     0x55d6a7994fa5 - std::panicking::default_hook::{{closure}}::h1ee5b7d8b6f83429
                               at src/libstd/panicking.rs:204
   9:     0x55d6a7994cf2 - std::panicking::default_hook::hd6c32c13403f9210
                               at src/libstd/panicking.rs:224
  10:     0x55d6a7995562 - std::panicking::rust_panic_with_hook::h1f2449d529a25f22
                               at src/libstd/panicking.rs:470
  11:     0x55d6a798b441 - std::panicking::begin_panic::h5a36cc3b26b56542
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd/src/libstd/panicking.rs:397
  12:     0x55d6a798540a - <glib::object::Object as glib::translate::FromGlibPtrBorrow<*mut gobject_sys::GObject>>::from_glib_borrow::hfc80280ad2f153ca
                               at /home/wiky/.cargo/registry/src/github.com-1ecc6299db9ec823/gio-0.8.1/<::std::macros::panic macros>:2
  13:     0x55d6a79849ee - glib::translate::from_glib_borrow::h80f9642bc3606747
                               at /home/wiky/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-0.9.3/src/translate.rs:1228
  14:     0x55d6a7983498 - <O as gio::auto::threaded_socket_service::ThreadedSocketServiceExt>::connect_run::run_trampoline::hb9b61c2da889377e
                               at /home/wiky/.cargo/registry/src/github.com-1ecc6299db9ec823/gio-0.8.1/src/auto/threaded_socket_service.rs:87
  15:     0x7f6b126f53b7 - <unknown>
  16:     0x7f6b12625a56 - <unknown>
  17:     0x7f6b12643dd1 - g_signal_emit_valist
  18:     0x7f6b126450d3 - g_signal_emit
  19:     0x7f6b12729e39 - <unknown>
  20:     0x7f6b125641d4 - <unknown>
  21:     0x7f6b12563931 - <unknown>
  22:     0x7f6b124c8609 - start_thread
  23:     0x7f6b123d2103 - __clone
  24:                0x0 - <unknown>
fatal runtime error: failed to initiate panic, error 5
Aborted (core dumped)

@sdroege
Copy link
Member

sdroege commented Jun 2, 2020

Indeed, fixing. Thanks for reporting :)

@sdroege
Copy link
Member

sdroege commented Jun 2, 2020

See #301

@wikylyu
Copy link
Author

wikylyu commented Jun 2, 2020

That's cool. thanks for your work. And when will new version be released?

@sdroege
Copy link
Member

sdroege commented Jun 2, 2020

In 2-3 weeks I hope

GuillaumeGomez pushed a commit to gtk-rs/gtk3-rs that referenced this issue Oct 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants