Git Product home page Git Product logo

tokio-middleware's People

Contributors

alexcrichton avatar aturon avatar bippityboppity avatar carllerche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tokio-middleware's Issues

Logging responses and errors

Log is very useful for logging requests, but it would be even more useful if it logged responses and errors too.

I've enhanced Log to do this on my fork (at matt-williams@e842043).

Would you be interested in taking this upstream? I'm happy to submit a pull request if so - please let me know.

Add example using tokio-service

#Is it possible for someone to add a complete example using tokio-service with one of these middleware layers?

When using the middleware approach with tokio-service like so:

TcpServer::new(Http, addr).serve(|| Ok(MiddlewareService::new(UpstreamService, "someExtraState"));

I get:

expected a closure that implements the Fn trait, but this closure only implements 'FnOnce' .

I think understand why this is the case, but wondering what the right way to use middleware with tokio-service is now. :)

The big question I have in my mind is how I initialize one of these middleware layers (i.e., call ::new() on the thing, but still pass in a type for the tokio-service layer to do its thing. I see that Timeout middleware asks for state (upstream, timeout duration, etc) so I thought it would be a good complete example.

Getting occasionally 'other was less than the current instant' in Timeout middleware

I am trying to add request/response timeout for TcpClient. My implementation is shown below

    pub fn connect_with_timeout (address: &String, timeout: Duration) -> io::Result<Client> {
        let mut core = Core::new()?;
        let address = address.parse().unwrap();
        let future = Box::new(TcpClient::new(BytesClientProto)
                                  .connect(&address, &core.handle())
                                  .map(|c| Timeout::new(
                                      ClientCore {
                                          inner: c,
                                      },
                                      Timer::default(),
                                      timeout)));
        let client = core.run(future)?;
        Ok(Client {
            client: client,
            core: Box::new(core),
        })
    }

The error seems panicked from tokio_time, not sure if it is because I didn't use it right.

stack backtrace:
   1:     0x7f4f85da9c2c - std::sys::imp::backtrace::tracing::imp::write::h2a972e172776bc73
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7f4f85db7f5e - std::panicking::default_hook::{{closure}}::h3350be9abe4c8496
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:351
   3:     0x7f4f85db7b64 - std::panicking::default_hook::h255964940ef72e84
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:367
   4:     0x7f4f85db8407 - std::panicking::rust_panic_with_hook::ha02a85ff57cdb669
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:555
   5:     0x7f4f85db8294 - std::panicking::begin_panic::hd282678ae37b0eee
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:517
   6:     0x7f4f85da5820 - <std::time::Instant as core::ops::Sub>::sub::he30b60fd7a8aab38
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/time.rs:276
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libcore/result.rs:714
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/time.rs:275
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/time/mod.rs:143
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/time/mod.rs:208
   7:     0x5619854cb7e7 - tokio_timer::worker::run::h1784171f754e877f
                        at /home/shisoft/.cargo/git/checkouts/tokio-timer-d282e7d6c658dca8/4acaed6/src/worker.rs:170
   8:     0x5619854c9c03 - tokio_timer::worker::Worker::spawn::{{closure}}::h5b11fa2442eb3044
                        at /home/shisoft/.cargo/git/checkouts/tokio-timer-d282e7d6c658dca8/4acaed6/src/worker.rs:64
   9:     0x5619854c056f - <std::panic::AssertUnwindSafe<F> as core::ops::FnOnce<()>>::call_once::hfebfd6a327f96b86
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panic.rs:296
  10:     0x5619854b3a6a - std::panicking::try::do_call::h58acbe5fbbeb3eb6
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:460
  11:     0x7f4f85dc126a - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
  12:     0x5619854b3575 - std::panicking::try::h5e5bb5f8361aec88
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:436
  13:     0x5619854b2249 - std::panic::catch_unwind::he6601d08a33dd185
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panic.rs:361
  14:     0x5619854b30d7 - std::thread::Builder::spawn::{{closure}}::h828d914eb25efe61
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/mod.rs:302
  15:     0x5619854bbe99 - <F as alloc::boxed::FnBox<A>>::call_box::hb4d683a80c5acbbd
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:605
  16:     0x7f4f85db6dc4 - std::sys::imp::thread::Thread::new::thread_start::h27fa49fe81f658e4
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:615
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys_common/thread.rs:21
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84

Any clues are welcome.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.