Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deregistering TcpListener on Windows doesn't work #1073

Closed
Thomasdezeeuw opened this issue Aug 31, 2019 · 2 comments
Closed

Deregistering TcpListener on Windows doesn't work #1073

Thomasdezeeuw opened this issue Aug 31, 2019 · 2 comments
Assignees
Labels
windows Related to the Windows OS.
Milestone

Comments

@Thomasdezeeuw
Copy link
Collaborator

See #1070, relevant CI logs is available here: https://dev.azure.com/tokio-rs/Tokio/_build/results?buildId=2274&view=logs&jobId=429a383f-e486-57ac-3982-9ac65641a32a&taskId=1f926ffb-0ec7-5f9b-ab05-76fbb04597a8&lineStart=150&lineEnd=151&colStart=1&colEnd=1. Relevant test is available here: https://github.com/Thomasdezeeuw/mio/blob/add262520f777d5564c26b7f2fc8596a07c4e83f/tests/tcp_listener.rs#L156-L185.

/cc @PerfectLaugh


Copy of the log and code, for when the links above don't work anymore.

---- deregister stdout ----
[ERROR tcp_listener::util] unexpected event: Event { token: Token(0), readable: true, writable: false, error: false, hup: false, read_hup: false, priority: false, aio: false, lio: false }
thread 'deregister' panicked at 'received events, but didn't expect any, see above', tests\util\mod.rs:180:9
stack backtrace:
   0:     0x7ff75223807c - backtrace::backtrace::trace_unsynchronized
                               at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.29\src\backtrace\mod.rs:66
   1:     0x7ff75223807c - std::sys_common::backtrace::_print
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\sys_common\backtrace.rs:47
   2:     0x7ff75223b52e - std::sys_common::backtrace::print
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\sys_common\backtrace.rs:36
   3:     0x7ff75223b52e - std::panicking::default_hook::{{closure}}
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\panicking.rs:200
   4:     0x7ff75223b13b - std::panicking::default_hook
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\panicking.rs:211
   5:     0x7ff75223bdc0 - std::panicking::rust_panic_with_hook
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\panicking.rs:477
   6:     0x7ff7521f89c1 - std::panicking::begin_panic<str*>
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\panicking.rs:411
   7:     0x7ff75218b801 - tcp_listener::util::expect_no_events
                               at D:\a\1\s\tests\util\mod.rs:180
   8:     0x7ff752185ae6 - tcp_listener::deregister
                               at D:\a\1\s\tests\tcp_listener.rs:171
   9:     0x7ff752188b2e - tcp_listener::deregister::{{closure}}
                               at D:\a\1\s\tests\tcp_listener.rs:156
  10:     0x7ff752181e0b - core::ops::function::FnOnce::call_once<closure,()>
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libcore\ops\function.rs:231
  11:     0x7ff7521bdef7 - alloc::boxed::{{impl}}::call_once<(),FnOnce<()>>
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\liballoc\boxed.rs:746
  12:     0x7ff752240682 - panic_unwind::__rust_maybe_catch_panic
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libpanic_unwind\lib.rs:82
  13:     0x7ff7521dcefb - std::panicking::try
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\panicking.rs:275
  14:     0x7ff7521dcefb - std::panic::catch_unwind
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\panic.rs:394
  15:     0x7ff7521dcefb - test::run_test::run_test_inner::{{closure}}
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libtest\lib.rs:1466
  16:     0x7ff7521afd7e - std::sys_common::backtrace::__rust_begin_short_backtrace<closure,()>
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\sys_common\backtrace.rs:77
  17:     0x7ff7521b5c0e - std::thread::{{impl}}::spawn_unchecked::{{closure}}::{{closure}}
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\thread\mod.rs:470
  18:     0x7ff7521b5c0e - std::panic::{{impl}}::call_once
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\panic.rs:315
  19:     0x7ff7521b5c0e - std::panicking::try::do_call<std::panic::AssertUnwindSafe<closure>,()>
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\panicking.rs:296
  20:     0x7ff752240682 - panic_unwind::__rust_maybe_catch_panic
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libpanic_unwind\lib.rs:82
  21:     0x7ff7521b6350 - std::panicking::try
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\panicking.rs:275
  22:     0x7ff7521b6350 - std::panic::catch_unwind
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\panic.rs:394
  23:     0x7ff7521b6350 - std::thread::{{impl}}::spawn_unchecked::{{closure}}
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libstd\thread\mod.rs:469
  24:     0x7ff7521b6350 - core::ops::function::FnOnce::call_once<closure,()>
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\libcore\ops\function.rs:231
  25:     0x7ff75222a7a7 - alloc::boxed::{{impl}}::call_once<(),FnOnce<()>>
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\liballoc\boxed.rs:746
  26:     0x7ff75223f337 - alloc::boxed::{{impl}}::call_once
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\src\liballoc\boxed.rs:746
  27:     0x7ff75223f337 - std::sys_common::thread::start_thread
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\sys_common\thread.rs:13
  28:     0x7ff75223f337 - std::sys::windows::thread::{{impl}}::new::thread_start
                               at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b\/src\libstd\sys\windows\thread.rs:47
  29:     0x7ffd98cc84d4 - BaseThreadInitThunk
  30:     0x7ffd98eae851 - RtlUserThreadStart
#[test]
fn deregister() {
    let (mut poll, mut events) = init_with_poll();

    let listener = TcpListener::bind(any_local_address()).unwrap();
    let address = listener.local_addr().unwrap();

    poll.registry()
        .register(&listener, ID1, Interests::READABLE)
        .unwrap();

    let barrier = Arc::new(Barrier::new(2));
    let thread_handle = start_connections(address, 1, barrier.clone());

    poll.registry().deregister(&listener).unwrap();

    expect_no_events(&mut poll, &mut events);

    // Should still be able to accept the connection.
    let (stream, peer_address) = listener.accept().expect("unable to accept connection");
    assert!(peer_address.ip().is_loopback());
    assert_eq!(stream.peer_addr().unwrap(), peer_address);
    assert_eq!(stream.local_addr().unwrap(), address);

    assert_would_block(listener.accept());

    assert!(listener.take_error().unwrap().is_none());

    barrier.wait();
    thread_handle.join().expect("unable to join thread");
}
@Thomasdezeeuw Thomasdezeeuw added the windows Related to the Windows OS. label Aug 31, 2019
@Thomasdezeeuw Thomasdezeeuw added this to the v0.7 milestone Aug 31, 2019
@carllerche carllerche mentioned this issue Sep 12, 2019
16 tasks
dtacalau added a commit to dtacalau/mio that referenced this issue Nov 7, 2019
…en deregistering a socket make sure it is marked for deletion so it won't be used in poll updates.

Signed-off-by: Daniel Tacalau <dst4096@gmail.com>
@dtacalau
Copy link
Contributor

dtacalau commented Nov 7, 2019

@Thomasdezeeuw please assign this issue to me, I've started working on it.

dtacalau added a commit to dtacalau/mio that referenced this issue Nov 8, 2019
…on windows. When deregistering a socket make sure it is marked for deletion so it won't be used in poll updates.

Signed-off-by: Daniel Tacalau <dst4096@gmail.com>
dtacalau added a commit to dtacalau/mio that referenced this issue Nov 8, 2019
… windows. When deregistering a socket make sure it is marked for deletion so it won't be used in poll updates. Also added a new more complicated test for TcpStream deregistering and fixed the existing test which was mistankenly registering only READABLE instead of WRITABLE.

Signed-off-by: Daniel Tacalau <dst4096@gmail.com>
@dtacalau
Copy link
Contributor

dtacalau commented Nov 8, 2019

Deregistering did not worked for TcpListener, TcpStream, UdpSocket but the error was not caught everywhere. To fix this the socket state should be marked for deletion upon deregistering so it cannot be used in any subsequent poll updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Related to the Windows OS.
Projects
None yet
Development

No branches or pull requests

2 participants