tokio-rs / tokio-core

I/O primitives and event loop for async I/O in Rust
Apache License 2.0
640 stars 115 forks source link

0.1.13 breaks registering an fd on multiple event loops #307

Closed alexcrichton closed 6 years ago

alexcrichton commented 6 years ago

Since 0.1.13 the tests for tokio-signal have started failing with an error along the lines of Error { repr: Os { code: 17, message: "File exists" } }.

It looks like prints two successes in 0.1.12 and only one in 0.1.13:

extern crate tokio_core;
extern crate mio;

use mio::*;
use std::io;
use mio::unix::*;
use std::net::TcpListener;
use std::os::unix::prelude::*;
use tokio_core::reactor::{Core, PollEvented};

fn main() {
    let a = Core::new().unwrap();
    let b = Core::new().unwrap();

    let l = TcpListener::bind("127.0.0.1:0").unwrap();

    println!("{:?}", PollEvented::new(Custom(l.as_raw_fd()), &a.handle()));
    println!("{:?}", PollEvented::new(Custom(l.as_raw_fd()), &b.handle()));
}

#[derive(Debug)]
struct Custom(i32);

impl Evented for Custom {
    fn register(&self, poll: &Poll, token: Token, events: Ready, opts: PollOpt) -> io::Result<()> {
        EventedFd(&self.0).register(poll, token, events, opts)
    }
    fn reregister(&self, poll: &Poll, token: Token, events: Ready, opts: PollOpt) -> io::Result<()> {
        EventedFd(&self.0).reregister(poll, token, events, opts)
    }
    fn deregister(&self, poll: &Poll) -> io::Result<()> {
        EventedFd(&self.0).deregister(poll)
    }
}
carllerche commented 6 years ago

Thanks for the report.

I tried running the snippet w/ tokio-core 0.1.13 but get 2 successes. Do you have more info on how to reproduce? What OS, etc... maybe post the full Cargo.lock?

carllerche commented 6 years ago

Ok, this does seem to happen on Linux only and not OS X.

alexcrichton commented 6 years ago

Yes, the OS Travis is using in the test logs above is Linux and I was testing with Linux locally.

carllerche commented 6 years ago

I opened https://github.com/tokio-rs/tokio-core/pull/308 which should fix the issue.

I used it to successfully run the tokio-signal tests. Would you mind double confirming this fixes the issue as you see it? I can release a fix once this gets merged.