1

我开始使用actix-web 使用actix web 指南入门部分中的示例。运行代码时,我收到似乎来自 actix 框架的运行时错误。

版本:

  • 赢10
  • rustc 1.33.0 (2aa4c46cf 2019-02-28)
  • actix-web 0.7.18

这是代码:

extern crate actix_web;
use std::env;
use actix_web::{server, App, HttpRequest};

fn index(_req: &HttpRequest) -> &'static str {
    "Hello World!"
}

fn main() {
    env::set_var("RUST_BACKTRACE","1");

    server::new(
        || App::new()
            .resource("/", |r| r.f(index)))
        .bind("127.0.0.1:8088")
        .unwrap()
        .run();
}

它编译正常,但我得到以下回溯,回溯中的相关行似乎是第 11 行似乎发生了恐慌,第 73 行显示了我的主函数中最终导致恐慌的调用。

我仔细检查了端口 8088 是否可用。我究竟做错了什么?

   Compiling hello_cargo v0.1.0 (D:\users\Jan Debeuckelaer\projects\hello_cargo)
    Finished dev [unoptimized + debuginfo] target(s) in 7.97s
     Running `target\debug\hello_cargo.exe`
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src\libcore\option.rs:345:21
stack backtrace:
   0: std::sys::windows::backtrace::set_frames
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys\windows\backtrace\mod.rs:94
   1: std::sys::windows::backtrace::unwind_backtrace
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys\windows\backtrace\mod.rs:81
   2: std::sys_common::backtrace::_print
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys_common\backtrace.rs:70
   3: std::sys_common::backtrace::print
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sys_common\backtrace.rs:58
   4: std::panicking::default_hook::{{closure}}
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:200
   5: std::panicking::default_hook
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:215
   6: std::panicking::rust_panic_with_hook
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:478
   7: std::panicking::continue_panic_fmt
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:385
   8: std::panicking::rust_begin_panic
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:312
   9: core::panicking::panic_fmt
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libcore\panicking.rs:85
  10: core::panicking::panic
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libcore\panicking.rs:49
  11: core::option::Option<(mio::poll::Registration, mio::poll::SetReadiness)*>::unwrap<(mio::poll::Registration, mio::poll::SetReadiness)*>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libcore\macros.rs:10
  12: tokio_signal::windows::global_init
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-signal-0.2.8\src\windows.rs:165
  13: tokio_signal::windows::{{impl}}::new::{{closure}}
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-signal-0.2.8\src\windows.rs:118
  14: std::sync::once::{{impl}}::call_once::{{closure}}<closure>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\sync\once.rs:220
  15: std::sync::once::Once::call_inner
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\sync\once.rs:387
  16: std::sync::once::Once::call_once<closure>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\sync\once.rs:220
  17: tokio_signal::windows::Event::new
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-signal-0.2.8\src\windows.rs:117
  18: tokio_signal::windows::Event::ctrl_c_handle
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-signal-0.2.8\src\windows.rs:96
  19: tokio_signal::ctrl_c_handle::ctrl_c_imp::{{closure}}
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-signal-0.2.8\src\lib.rs:137
  20: futures::future::lazy::Lazy<closure, futures::future::map::Map<alloc::boxed::Box<Future>, closure>>::get<closure,futures::future::map::Map<alloc::boxed::Box<Future>, closure>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\future\lazy.rs:64
  21: futures::future::lazy::{{impl}}::poll<closure,futures::future::map::Map<alloc::boxed::Box<Future>, closure>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\future\lazy.rs:82
  22: futures::future::{{impl}}::poll<Future>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\future\mod.rs:113
  23: futures::future::map_err::{{impl}}::poll<(),alloc::boxed::Box<Future>,closure>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\future\map_err.rs:30
  24: actix::fut::{{impl}}::poll<futures::future::map_err::MapErr<alloc::boxed::Box<Future>, closure>,actix::actors::signal::ProcessSignals>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\actix-0.7.9\src\fut\mod.rs:389
  25: actix::fut::map::{{impl}}::poll<(),actix::fut::FutureWrap<futures::future::map_err::MapErr<alloc::boxed::Box<Future>, closure>, actix::actors::signal::ProcessSignals>,closure>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\actix-0.7.9\src\fut\map.rs:38
  26: actix::fut::{{impl}}::poll<ActorFuture>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\actix-0.7.9\src\fut\mod.rs:313
  27: actix::contextimpl::{{impl}}::poll<actix::actors::signal::ProcessSignals,actix::context::Context<actix::actors::signal::ProcessSignals>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\actix-0.7.9\src\contextimpl.rs:355
  28: actix::supervisor::{{impl}}::poll<actix::actors::signal::ProcessSignals>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\actix-0.7.9\src\supervisor.rs:147
  29: futures::future::{{impl}}::poll<actix::supervisor::Supervisor<actix::actors::signal::ProcessSignals>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\future\mod.rs:113
  30: futures::future::{{impl}}::poll<Future>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\future\mod.rs:113
  31: futures::task_impl::{{impl}}::poll_future_notify::{{closure}}<alloc::boxed::Box<Future>,tokio_current_thread::scheduler::Notify<tokio_reactor::Handle>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\task_impl\mod.rs:326
  32: futures::task_impl::{{impl}}::enter::{{closure}}<alloc::boxed::Box<Future>,closure,core::result::Result<futures::poll::Async<()>, ()>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\task_impl\mod.rs:396
  33: futures::task_impl::std::set<closure,core::result::Result<futures::poll::Async<()>, ()>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\task_impl\std\mod.rs:78
  34: futures::task_impl::Spawn<alloc::boxed::Box<Future>>::enter<alloc::boxed::Box<Future>,closure,core::result::Result<futures::poll::Async<()>, ()>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\task_impl\mod.rs:396
  35: futures::task_impl::Spawn<alloc::boxed::Box<Future>>::poll_fn_notify<alloc::boxed::Box<Future>,tokio_current_thread::scheduler::Notify<tokio_reactor::Handle>,closure,core::result::Result<futures::poll::Async<()>, ()>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\task_impl\mod.rs:288
  36: futures::task_impl::Spawn<alloc::boxed::Box<Future>>::poll_future_notify<alloc::boxed::Box<Future>,tokio_current_thread::scheduler::Notify<tokio_reactor::Handle>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-0.1.25\src\task_impl\mod.rs:326
  37: tokio_current_thread::scheduler::Scheduled<tokio_reactor::Handle>::tick<tokio_reactor::Handle>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-current-thread-0.1.6\src\scheduler.rs:351
  38: tokio_current_thread::scheduler::{{impl}}::tick::{{closure}}<tokio_reactor::Handle>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-current-thread-0.1.6\src\scheduler.rs:330
  39: tokio_current_thread::{{impl}}::enter::{{closure}}::{{closure}}<tokio_reactor::Handle,closure,bool>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-current-thread-0.1.6\src\lib.rs:788
  40: tokio_current_thread::CurrentRunner::set_spawn<closure,bool>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-current-thread-0.1.6\src\lib.rs:825
  41: tokio_current_thread::{{impl}}::enter::{{closure}}<tokio_reactor::Handle,closure,bool>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-current-thread-0.1.6\src\lib.rs:788
  42: std::thread::local::LocalKey<tokio_current_thread::CurrentRunner>::try_with<tokio_current_thread::CurrentRunner,closure,bool>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:299
  43: std::thread::local::LocalKey<tokio_current_thread::CurrentRunner>::with<tokio_current_thread::CurrentRunner,closure,bool>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:245
  44: tokio_current_thread::Borrow<tokio_reactor::Handle>::enter<tokio_reactor::Handle,closure,bool>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-current-thread-0.1.6\src\lib.rs:786
  45: tokio_current_thread::scheduler::Scheduler<tokio_reactor::Handle>::tick<tokio_reactor::Handle>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-current-thread-0.1.6\src\scheduler.rs:330
  46: tokio_current_thread::Entered<tokio_timer::timer::Timer<tokio_reactor::Reactor, tokio_timer::clock::clock::Clock>>::tick<tokio_timer::timer::Timer<tokio_reactor::Reactor, tokio_timer::clock::clock::Clock>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-current-thread-0.1.6\src\lib.rs:612
  47: tokio_current_thread::Entered<tokio_timer::timer::Timer<tokio_reactor::Reactor, tokio_timer::clock::clock::Clock>>::block_on<tokio_timer::timer::Timer<tokio_reactor::Reactor, tokio_timer::clock::clock::Clock>,futures::sync::oneshot::Receiver<i32>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-current-thread-0.1.6\src\lib.rs:502
  48: tokio::runtime::current_thread::runtime::{{impl}}::block_on::{{closure}}<futures::sync::oneshot::Receiver<i32>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.1.18\src\runtime\current_thread\runtime.rs:200
  49: tokio::runtime::current_thread::runtime::{{impl}}::enter::{{closure}}::{{closure}}::{{closure}}::{{closure}}<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.1.18\src\runtime\current_thread\runtime.rs:241
  50: tokio_executor::global::with_default::{{closure}}<tokio_current_thread::TaskExecutor,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-executor-0.1.7\src\global.rs:209
  51: std::thread::local::LocalKey<core::cell::Cell<tokio_executor::global::State>>::try_with<core::cell::Cell<tokio_executor::global::State>,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:299
  52: std::thread::local::LocalKey<core::cell::Cell<tokio_executor::global::State>>::with<core::cell::Cell<tokio_executor::global::State>,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:245
  53: tokio_executor::global::with_default<tokio_current_thread::TaskExecutor,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-executor-0.1.7\src\global.rs:178
  54: tokio::runtime::current_thread::runtime::{{impl}}::enter::{{closure}}::{{closure}}::{{closure}}<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.1.18\src\runtime\current_thread\runtime.rs:239
  55: tokio_timer::timer::handle::with_default::{{closure}}<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-timer-0.2.10\src\timer\handle.rs:94
  56: std::thread::local::LocalKey<core::cell::RefCell<core::option::Option<tokio_timer::timer::handle::HandlePriv>>>::try_with<core::cell::RefCell<core::option::Option<tokio_timer::timer::handle::HandlePriv>>,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:299
  57: std::thread::local::LocalKey<core::cell::RefCell<core::option::Option<tokio_timer::timer::handle::HandlePriv>>>::with<core::cell::RefCell<core::option::Option<tokio_timer::timer::handle::HandlePriv>>,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:245
  58: tokio_timer::timer::handle::with_default<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-timer-0.2.10\src\timer\handle.rs:81
  59: tokio::runtime::current_thread::runtime::{{impl}}::enter::{{closure}}::{{closure}}<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.1.18\src\runtime\current_thread\runtime.rs:232
  60: tokio_timer::clock::clock::with_default::{{closure}}<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-timer-0.2.10\src\clock\clock.rs:141
  61: std::thread::local::LocalKey<core::cell::Cell<core::option::Option<const tokio_timer::clock::clock::Clock*>>>::try_with<core::cell::Cell<core::option::Option<const tokio_timer::clock::clock::Clock*>>,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:299
  62: std::thread::local::LocalKey<core::cell::Cell<core::option::Option<const tokio_timer::clock::clock::Clock*>>>::with<core::cell::Cell<core::option::Option<const tokio_timer::clock::clock::Clock*>>,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:245
  63: tokio_timer::clock::clock::with_default<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-timer-0.2.10\src\clock\clock.rs:124
  64: tokio::runtime::current_thread::runtime::{{impl}}::enter::{{closure}}<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.1.18\src\runtime\current_thread\runtime.rs:231
  65: tokio_reactor::with_default::{{closure}}<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-reactor-0.1.9\src\lib.rs:237
  66: std::thread::local::LocalKey<core::cell::RefCell<core::option::Option<tokio_reactor::HandlePriv>>>::try_with<core::cell::RefCell<core::option::Option<tokio_reactor::HandlePriv>>,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:299
  67: std::thread::local::LocalKey<core::cell::RefCell<core::option::Option<tokio_reactor::HandlePriv>>>::with<core::cell::RefCell<core::option::Option<tokio_reactor::HandlePriv>>,closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\thread\local.rs:245
  68: tokio_reactor::with_default<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-reactor-0.1.9\src\lib.rs:217
  69: tokio::runtime::current_thread::runtime::Runtime::enter<closure,core::result::Result<i32, futures::sync::oneshot::Canceled>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.1.18\src\runtime\current_thread\runtime.rs:230
  70: tokio::runtime::current_thread::runtime::Runtime::block_on<futures::sync::oneshot::Receiver<i32>>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.1.18\src\runtime\current_thread\runtime.rs:198
  71: actix::system::SystemRunner::run
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\actix-0.7.9\src\system.rs:174
  72: actix_web::server::http::HttpServer<actix_web::application::App<()>, closure>::run<actix_web::application::App<()>,closure>
             at C:\Users\Jan Debeuckelaer\.cargo\registry\src\github.com-1ecc6299db9ec823\actix-web-0.7.18\src\server\http.rs:539
  73: hello_cargo::main
             at .\src\main.rs:12
  74: std::rt::lang_start::{{closure}}<()>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\rt.rs:64
  75: std::rt::lang_start_internal::{{closure}}
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\rt.rs:49
  76: std::panicking::try::do_call<closure,i32>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:297
  77: panic_unwind::__rust_maybe_catch_panic
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libpanic_unwind\lib.rs:92
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panicking.rs:276
  79: std::panic::catch_unwind
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\panic.rs:388
  80: std::rt::lang_start_internal
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\/src\libstd\rt.rs:48
  81: std::rt::lang_start<()>
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858\src\libstd\rt.rs:64
  83: invoke_main
             at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  84: __scrt_common_main_seh
             at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  85: BaseThreadInitThunk
  86: RtlUserThreadStart
Panic in Arbiter thread, shutting down system.
4

1 回答 1

2

我也发现了这一点,我认为这与 tokio lib 中的这两个问题有关:

于 2019-03-24T16:10:03.060 回答