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

Asynchronous middleware that runs after synchronous middleware panics during execution. #226

Closed
mitskevich opened this issue May 16, 2018 · 2 comments

Comments

@mitskevich
Copy link

mitskevich commented May 16, 2018

Asynchronous middleware that runs after synchronous middleware panics during execution.

Example:

extern crate actix_web;
extern crate futures;

use actix_web as aw;
use actix_web::middleware::{Middleware, Started};
use futures::future;

struct AsyncMiddleware;

impl<S> Middleware<S> for AsyncMiddleware {
    fn start(&self, _req: &mut aw::HttpRequest<S>) -> Result<Started, aw::Error> {
        Ok(Started::Future(Box::new(future::ok(None))))
    }
}

struct SyncMiddleware;

impl<S> Middleware<S> for SyncMiddleware {
    fn start(&self, _req: &mut aw::HttpRequest<S>) -> Result<Started, aw::Error> {
        Ok(Started::Done)
    }
}

fn index(_info: aw::Path<()>) -> String {
   format!("Hello!")
}

fn main() {
    aw::server::new(
        || aw::App::new()
            .middleware(AsyncMiddleware)
            .middleware(SyncMiddleware)
            .resource("index", |r| r.with(index)))
        .bind("0.0.0.0:8080").unwrap()
        .run();
}

Running this code and opening http://localhost:8080/index results in the following panic:

thread 'arbiter:"0bb027f8-ed1c-4c82-b536-abc9c30b705d":"actor"' panicked at 'index out of bounds: the len is 2 but the index is 2', /Users/travis/build/rust-lang/rust/src/libcore/slice/mod.rs:865:10
stack backtrace:
   0:        0x1026258db - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h971d95e9e3db308e
                               at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:        0x1026173cb - std::sys_common::backtrace::print::h4029c802e44d6cdd
                               at libstd/sys_common/backtrace.rs:71
                               at libstd/sys_common/backtrace.rs:59
   2:        0x1026211bd - std::panicking::default_hook::{{closure}}::h1ecea4a975914b6f
                               at libstd/panicking.rs:207
   3:        0x102620f1a - std::panicking::default_hook::h7cf0c6fc3b540dfe
                               at libstd/panicking.rs:223
   4:        0x102621636 - std::panicking::begin_panic::h922abe9fce293715
                               at libstd/panicking.rs:402
   5:        0x10262146a - std::panicking::try::do_call::hc7b9e6190a1d9f3e
                               at libstd/panicking.rs:349
   6:        0x102621362 - std::panicking::try::do_call::hc7b9e6190a1d9f3e
                               at libstd/panicking.rs:325
   7:        0x102661575 - core::ptr::drop_in_place::h4855c6c9f0f14c94
                               at libcore/panicking.rs:72
   8:        0x1026614f3 - core::ptr::drop_in_place::h4855c6c9f0f14c94
                               at libcore/panicking.rs:58
   9:        0x101f53d15 - <usize as core::slice::SliceIndex<[T]>>::index::h65242a3d74408fb7
                               at /Users/travis/build/rust-lang/rust/src/libcore/slice/mod.rs:865
  10:        0x101f2f334 - core::slice::<impl core::ops::index::Index<I> for [T]>::index::h4771d63dafe842e7
                               at /Users/travis/build/rust-lang/rust/src/libcore/slice/mod.rs:767
  11:        0x101e8a7ea - <alloc::vec::Vec<T> as core::ops::index::Index<I>>::index::h148e8edf9156cdb3
                               at /Users/travis/build/rust-lang/rust/src/liballoc/vec.rs:1648
  12:        0x101f66de0 - <actix_web::pipeline::StartMiddlewares<S, H>>::poll::h8dbf65eb80373ad0
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-0.6.5/src/pipeline.rs:284
  13:        0x101f60265 - <actix_web::pipeline::PipelineState<S, H>>::poll::h94d1068e59e6d6aa
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-0.6.5/src/pipeline.rs:59
  14:        0x101f5ee3a - <actix_web::pipeline::Pipeline<S, H> as actix_web::server::HttpHandlerTask>::poll_io::ha1b83b1d3dc5f24f
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-0.6.5/src/pipeline.rs:200
  15:        0x101ea0fac - <actix_web::server::h1::Http1<T, H>>::poll_handler::h1d42c3d1c715bad5
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-0.6.5/src/server/h1.rs:199
  16:        0x101ea3476 - <actix_web::server::h1::Http1<T, H>>::poll::h5cf9f117ca970540
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-0.6.5/src/server/h1.rs:137
  17:        0x101f3b7a0 - <actix_web::server::channel::HttpChannel<T, H> as futures::future::Future>::poll::h7795c34ab56584b0
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-0.6.5/src/server/channel.rs:111
  18:        0x101f3c407 - <actix_web::server::channel::HttpChannel<T, H> as futures::future::Future>::poll::h7795c34ab56584b0
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-0.6.5/src/server/channel.rs:174
  19:        0x10229a274 - <alloc::boxed::Box<F> as futures::future::Future>::poll::hfb90946feb121de7
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.21/src/future/mod.rs:113
  20:        0x1022b0a94 - <futures::task_impl::Spawn<T>>::poll_future_notify::{{closure}}::h0ab248a8acc874a7
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.21/src/task_impl/mod.rs:289
  21:        0x1022b0ffa - <futures::task_impl::Spawn<T>>::enter::{{closure}}::h378861c2d8ce9bbe
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.21/src/task_impl/mod.rs:363
  22:        0x1022bb128 - futures::task_impl::std::set::h1cd05e2c61fbfbab
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.21/src/task_impl/std/mod.rs:78
  23:        0x1022b0f97 - <futures::task_impl::Spawn<T>>::enter::ha7556f74fe7acea8
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.21/src/task_impl/mod.rs:363
  24:        0x1022b09f9 - <futures::task_impl::Spawn<T>>::poll_future_notify::h3e4b82b3edec8f97
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.21/src/task_impl/mod.rs:289
  25:        0x10229b383 - <tokio::executor::current_thread::scheduler::Scheduled<'a, U>>::tick::hf4d7705cfaaac095
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.6/src/executor/current_thread/scheduler.rs:352
  26:        0x10229acdc - <tokio::executor::current_thread::scheduler::Scheduler<U>>::tick::{{closure}}::h54b27a570e90e7d7
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.6/src/executor/current_thread/scheduler.rs:332
  27:        0x1022c34bc - <tokio::executor::current_thread::Borrow<'a, U>>::enter::{{closure}}::{{closure}}::hcc48ee3e1e05705d
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.6/src/executor/current_thread/mod.rs:688
  28:        0x1022c2d6f - tokio::executor::current_thread::CurrentRunner::set_spawn::h5eab5b4f89b049e8
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.6/src/executor/current_thread/mod.rs:720
  29:        0x1022c33ec - <tokio::executor::current_thread::Borrow<'a, U>>::enter::{{closure}}::h5b0a8090014ab294
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.6/src/executor/current_thread/mod.rs:687
  30:        0x1022b2381 - <std::thread::local::LocalKey<T>>::try_with::h6eac37f2b399eb01
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:290
  31:        0x1022b1514 - <std::thread::local::LocalKey<T>>::with::h48e37f282f2a48b6
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:244
  32:        0x1022c332a - <tokio::executor::current_thread::Borrow<'a, U>>::enter::h9bb7cb1c04e96277
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.6/src/executor/current_thread/mod.rs:686
  33:        0x10229abbf - <tokio::executor::current_thread::scheduler::Scheduler<U>>::tick::hdf3e3edf251b14da
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.6/src/executor/current_thread/scheduler.rs:332
  34:        0x1022c356d - <tokio::executor::current_thread::Entered<'a, P>>::tick::hf2ce776f23d6e9f1
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.6/src/executor/current_thread/mod.rs:572
  35:        0x1022c3691 - <tokio::executor::current_thread::Entered<'a, P>>::turn::h098087970c1bc3dd
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.6/src/executor/current_thread/mod.rs:515
  36:        0x1022a6cdd - tokio_core::reactor::Core::poll::{{closure}}::{{closure}}::{{closure}}::{{closure}}::h33e5fa7e46c5a682
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:298
  37:        0x102298007 - <scoped_tls::ScopedKey<T>>::set::hfa9a95fef5045c68
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-0.1.2/src/lib.rs:155
  38:        0x1022a711a - tokio_core::reactor::Core::poll::{{closure}}::{{closure}}::{{closure}}::h42571aba03f224ff
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:297
  39:        0x1022a84c8 - tokio_timer::timer::handle::with_default::{{closure}}::h34d5970264624e4e
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.3/src/timer/handle.rs:64
  40:        0x1022b2199 - <std::thread::local::LocalKey<T>>::try_with::h6bf160a5f49a28a2
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:290
  41:        0x1022b16ea - <std::thread::local::LocalKey<T>>::with::h8fe86ca64da5039b
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:244
  42:        0x1022a8387 - tokio_timer::timer::handle::with_default::hdf7a2a19ef6726a1
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.3/src/timer/handle.rs:56
  43:        0x1022a79f9 - tokio_core::reactor::Core::poll::{{closure}}::{{closure}}::h9d1943f005388064
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:275
  44:        0x102297921 - tokio_executor::global::with_default::{{closure}}::hb31d8ad1952323c9
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.2/src/global.rs:176
  45:        0x1022b1977 - <std::thread::local::LocalKey<T>>::try_with::h1d43a4b456a9b01b
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:290
  46:        0x1022b174a - <std::thread::local::LocalKey<T>>::with::hc84c37348d7f17ff
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:244
  47:        0x1022977d4 - tokio_executor::global::with_default::he4512017f4c16ebb
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.2/src/global.rs:150
  48:        0x1022a7a40 - tokio_core::reactor::Core::poll::{{closure}}::hf9c10016dde5429a
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:274
  49:        0x1022975af - tokio_reactor::with_default::{{closure}}::h851436993f0de63c
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.1/src/lib.rs:207
  50:        0x1022b1b98 - <std::thread::local::LocalKey<T>>::try_with::h3e3b5136f28eb7c8
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:290
  51:        0x1022b163a - <std::thread::local::LocalKey<T>>::with::h7d717bc221b61945
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/local.rs:244
  52:        0x102297431 - tokio_reactor::with_default::h57d4fb425d294470
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.1/src/lib.rs:199
  53:        0x1022a6b12 - tokio_core::net::tcp::TcpStream::poll_write::{{closure}}::h7b0504d07a6d3801
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:273
  54:        0x101ef8ca3 - tokio_core::reactor::Core::run::h3a5d350b0de0ba6a
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-core-0.1.17/src/reactor/mod.rs:248
  55:        0x101e6bf65 - actix::arbiter::Arbiter::new::{{closure}}::had3987d0ed46d665
                               at /Users/sam/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-0.5.6/src/arbiter.rs:95
  56:        0x101fb41c4 - std::sys_common::backtrace::__rust_begin_short_backtrace::he0fc35969dfa5a36
                               at /Users/travis/build/rust-lang/rust/src/libstd/sys_common/backtrace.rs:136
  57:        0x101e80d3b - std::thread::Builder::spawn::{{closure}}::{{closure}}::hda4c96cf2dbdf8bd
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/mod.rs:406
  58:        0x101f5e134 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h8a44cb7fb0a738b5
                               at /Users/travis/build/rust-lang/rust/src/libstd/panic.rs:296
  59:        0x101ef4e24 - std::panicking::try::do_call::h4d1e09151299fc37
                               at /Users/travis/build/rust-lang/rust/src/libstd/panicking.rs:306
  60:        0x1026342fe - panic_unwind::dwarf::eh::read_encoded_pointer::h607d3e9cb67c5e89
                               at libpanic_unwind/lib.rs:102
  61:        0x101ef4cf9 - std::panicking::try::hfec658bf10bc3c1c
                               at /Users/travis/build/rust-lang/rust/src/libstd/panicking.rs:285
  62:        0x101f5e244 - std::panic::catch_unwind::ha236733e8fd897c4
                               at /Users/travis/build/rust-lang/rust/src/libstd/panic.rs:361
  63:        0x101e807e8 - std::thread::Builder::spawn::{{closure}}::h43dba51c39ebe748
                               at /Users/travis/build/rust-lang/rust/src/libstd/thread/mod.rs:405
  64:        0x101e80e85 - <F as alloc::boxed::FnBox<A>>::call_box::h916bed859c234b40
                               at /Users/travis/build/rust-lang/rust/src/liballoc/boxed.rs:784
  65:        0x102627c67 - std::sys_common::thread::start_thread::hffc3810a6e03b74d
                               at /Users/travis/build/rust-lang/rust/src/liballoc/boxed.rs:794
                               at libstd/sys_common/thread.rs:24
  66:        0x102616198 - std::sys::unix::thread::Thread::new::thread_start::hbd2eb72915a2a86e
                               at libstd/sys/unix/thread.rs:90
  67:     0x7fffaac2793a - _pthread_body
  68:     0x7fffaac27886 - _pthread_start

Also, an interesting point: if I append synchronous middleware first, everything works. This code is working without panic:

fn main() {
    aw::server::new(
        || aw::App::new()
            .middleware(SyncMiddleware)
            .middleware(AsyncMiddleware)
            .resource("index", |r| r.with(index)))
        .bind("0.0.0.0:8080").unwrap()
        .run();
}

Using:
MacOS Sierra, rust 1.26.0, actix-web 0.6.5

@mitskevich mitskevich changed the title Asynchronous middleware that follows synchronous middleware panics during execution. Asynchronous middleware that runs after synchronous middleware panics during execution. May 16, 2018
@fafhrd91
Copy link
Member

thanks for report!

i will release new version in several hours

@mitskevich
Copy link
Author

thanks! master branch is working now

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

No branches or pull requests

2 participants