dpc / mioco.pre-0.9

Scalable, coroutine-based, asynchronous IO handling library for Rust programming language. (aka MIO COroutines).
Mozilla Public License 2.0
457 stars 30 forks source link

"socket already registered" error when running echo example #122

Closed aloucks closed 4 years ago

aloucks commented 8 years ago

mioco v0.4.1

$ rustc --version --verbose
rustc 1.9.0-nightly (c8b8eb1fd 2016-04-01)
binary: rustc
commit-hash: c8b8eb1fda90998832ba1cdf96a34dc676f7124b
commit-date: 2016-04-01
host: x86_64-pc-windows-gnu
release: 1.9.0-nightly

$ RUST_BACKTRACE=1 target/debug/echo.exe
Starting tcp echo server on V4(127.0.0.1:5555)
thread '<main>' panicked at 'register failed: Error { repr: Custom(Custom { kind: Other, error: StringError("socket already registered") }) }', ../src/libcore\result.rs:746
stack backtrace:
   0:           0x9442ba - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hff309ab1d83ffd90
   1:           0x9437d4 - std::panicking::default_hook::h08ad3bb09872855b
   2:           0x90615f - std::sys_common::unwind::begin_unwind_inner::hfa66df7b3e69707e
   3:           0x907ceb - std::sys_common::unwind::begin_unwind_fmt::h1952eb42d4b32c9d
   4:           0x93695b - rust_begin_unwind
   5:           0x958a15 - core::panicking::panic_fmt::ha6b3c19493c123b3
   6:           0x41abc9 - core::result::unwrap_failed::h8ef88a17914f2dff
                        at ../src/libcore/macros.rs:29
   7:           0x442f5b - _<std..result..Result<T, E>>::expect::hdaf276e0c425b331
                        at ../src/libcore/result.rs:708
   8:           0x442ec7 - _<T as mioco..evented..EventSourceTrait>::register::h269a86b0f007dda3
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/evented.rs:262
   9:           0x442dd2 - _<mioco..evented..RcEventSource<T> as mioco..evented..RcEventSourceTrait>::register::h4ae57510b9c26ea1
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/evented.rs:388
  10:           0x46ec97 - mioco::coroutine::Coroutine::register_all::h7e25f1d5fc32837f
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/coroutine.rs:406
  11:           0x46e559 - mioco::CoroutineControl::after_resume::h4aab2d217b84a89d
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/lib.rs:511
  12:           0x46c159 - mioco::CoroutineControl::resume::ha747a58c37adf5c6
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/lib.rs:505
  13:           0x46bc3b - _<FifoSchedulerThread as SchedulerThread>::ready::h3f9a8ad5eb884d26
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/lib.rs:448
  14:           0x49312d - _<thread..Handler as mio_orig..Handler>::ready::h16ec6e1e5b15a4a9
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/thread.rs:344
  15:           0x431229 - _<mioco..mio..EventLoop<H>>::io_event::h76def7321b8d98bb
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mio-0.5.0\src/event_loop.rs:343
  16:           0x431134 - _<mioco..mio..EventLoop<H>>::io_process::h896936efd5d72243
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mio-0.5.0\src/event_loop.rs:335
  17:           0x430288 - _<mioco..mio..EventLoop<H>>::run_once::h0bd7da29d417e7a9
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mio-0.5.0\src/event_loop.rs:298
  18:           0x42fb65 - _<mioco..mio..EventLoop<H>>::run::h5c3fadb94424b876
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mio-0.5.0\src/event_loop.rs:247
  19:           0x42495b - mioco::Mioco::thread_loop::hafedcaac4b4d5f54
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/lib.rs:726
  20:           0x417a34 - mioco::Mioco::run::hafc7a40413bb3a3f
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/lib.rs:680
  21:           0x401f02 - mioco::Mioco::start::hc604b9914e1d3f9c
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/lib.rs:625
  22:           0x401e17 - mioco::start::h73952a8455bf6e85
                        at G:\Users\Aaron\.cargo\registry\src\github.com-88ac128001ac3a9a\mioco-0.4.1\src/lib.rs:837
  23:           0x401840 - echo::main::hc184f21f24de94da
                        at src\bin/echo.rs:18
  24:           0x942e4d - std::sys_common::unwind::try::h6809d57ce7e089a3
  25:           0x942c7a - std::rt::lang_start::h12d9b3310b48a726
  26:           0x45c9ba - main
  27:           0x4013b4 - _tmainCRTStartup
  28:           0x4014e7 - mainCRTStartup
  29:         0x772259ec - strncmp
dpc commented 8 years ago

It looks like something was already using port 5555. If not, we're looking for people to help us fix Windows problems. eg. https://github.com/carllerche/mio/issues/367 .

I'll be happy to help, but I don't have Windows box, so I'm unable to help.

aloucks commented 8 years ago

The port was definitely not in use. The echo server starts up without issue; the error occurs as soon as a client connection is made. Probably related: https://github.com/carllerche/mio/issues/334

sbstp commented 8 years ago

I got this error when trying to read and write on the same socket from two different coroutines. Is the code made to support this?

dpc commented 8 years ago

Mioco code yes. But it's an mio windows error. I've recently maidsafe devs were hunting mio errors on windows, so we need to wait for these to get merged mainstream, them upgrade mioco's mio dependency.

sbstp commented 8 years ago

I was on linux when the bug occured. What I did was open 2 TcpStreams, clone them, spawn 2 coroutines, and pipe one socket into another in each coroutine, essentially joining the sockets together. It was panicking pretty often with the "socket already registered" error.

dpc commented 8 years ago

Can you share the code? Probably mioco bug then.

sbstp commented 8 years ago

It looks like this

let mut remote: TcpStream = ...;
let mut origin = try!(TcpStream::connect(&addr));

let mut remote2 = try!(remote.try_clone());
let mut origin2 = try!(origin.try_clone());

mioco::spawn(move || -> io::Result<()> {
    let mut buf = [0; 1024];
    loop {
        let size = try!(remote2.read(&mut buf));
        if size == 0 {
            break;
        }
        origin2.write_all(&buf[..size]);
    }
    Ok(())
});

mioco::spawn(move || -> io::Result<()> {
    let mut buf = [0; 1024];
    loop {
        let size = try!(origin.read(&mut buf));
        if size == 0 {
            break;
        }
        remote.write_all(&buf[..size]);
    }
    Ok(())
});