scottlamb / moonfire-nvr

Moonfire NVR, a security camera network video recorder
Other
1.22k stars 137 forks source link

panic when http server bind fails #136

Closed cholcombe973 closed 3 years ago

cholcombe973 commented 3 years ago

Describe the bug Pulling from the latest docker image it looks like i'm stuck in a crash loop. I did the normal setup and test and the test to the rstp url works from both the UI configurator and VLC. However when I start the docker container it seems to crash as soon as it tries to access the url.

To Reproduce Steps to reproduce the behavior:

  1. I'm following the basic setup instructions.
  2. I changed the docker options to:
    common_docker_run_args=(
        --mount=type=bind,source=/var/lib/moonfire-nvr,destination=/var/lib/moonfire-nvr
        --mount=type=bind,source=/mnt/raid/nvr,destination=/mnt/raid/nvr
        --user="$(id -u moonfire-nvr):$(id -g moonfire-nvr)"
        --security-opt=seccomp:unconfined
        --log-driver=journald
        --log-opt="tag=moonfire-nvr"
        --env=RUST_BACKTRACE=1
        --env=TZ=":${tz}"
    )

    and gave the moonfire-nvr user ownership of that directory.

  3. I ran the configuration UI ncurses setup
  4. Started the docker container with ./nvr.sh run and it crashes in a loop.

Expected behavior I'm expecting it to connect to the camera.

Screenshots If applicable, add screenshots to help explain your problem.

Server (please complete the following information):

chris@Workstation:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE scottlamb/moonfire-nvr latest bb6a1bc80ab1 4 weeks ago 735MB

  - If building from git: `git describe --dirty` + `moonfire-nvr --version`
  - Attach a [log file](https://github.com/scottlamb/moonfire-nvr/blob/master/guide/troubleshooting.md#viewing-moonfire-nvrs-logs). Run with the `RUST_BACKTRACE=1` environment variable set if possible.

I20210802 17:13:02.907 main moonfire_nvr::cmds] Opening /var/lib/moonfire-nvr/db/db in ReadWrite mode with SQLite version 3.31.1 I20210802 17:13:02.910 main moonfire_db::db] Loading video sample entries I20210802 17:13:02.910 main moonfire_db::db] Loaded 0 video sample entries I20210802 17:13:02.910 main moonfire_db::db] Loading sample file dirs I20210802 17:13:02.910 main moonfire_db::db] Loaded 2 sample file dirs I20210802 17:13:02.910 main moonfire_db::db] Loading cameras I20210802 17:13:02.910 main moonfire_db::db] Loaded 1 cameras I20210802 17:13:02.910 main moonfire_db::db] Loading streams I20210802 17:13:02.910 main moonfire_db::db] Loaded 2 streams I20210802 17:13:02.911 main moonfire_db::db] Loading recordings for camera lorex_1 stream Main I20210802 17:13:02.911 main moonfire_db::db] Loaded 0 recordings for camera lorex_1 stream Main I20210802 17:13:02.911 main moonfire_db::db] Loading recordings for camera lorex_1 stream Sub I20210802 17:13:02.911 main moonfire_db::db] Loaded 0 recordings for camera lorex_1 stream Sub I20210802 17:13:02.911 main moonfire_nvr::cmds::run] Database is loaded. I20210802 17:13:03.268 main moonfire_nvr::cmds::run] Directories are opened. I20210802 17:13:03.268 main moonfire_nvr::cmds::run] Resolved timezone: America/Los_Angeles I20210802 17:13:03.268 main moonfire_nvr::cmds::run] Starting syncer for path /mnt/raid/nvr I20210802 17:13:03.270 main moonfire_db::db] Flush 1 (why: synchronous deletion): no recording changes I20210802 17:13:03.270 main moonfire_nvr::cmds::run] Starting streamer for lorex_1-main I20210802 17:13:03.270 main moonfire_nvr::cmds::run] Starting streamer for lorex_1-sub I20210802 17:13:03.270 s-lorex_1-main moonfire_nvr::streamer] lorex_1-main: Opening input: rtsp://192.168.1.115:554/cam/realmonitor?channel=1&subtype=0 I20210802 17:13:03.270 s-lorex_1-sub moonfire_nvr::streamer] lorex_1-sub: Opening input: rtsp://192.168.1.115:554/cam/realmonitor?channel=1&subtype=1 E20210802 17:13:03.331 main moonfire_nvr] panic at '/var/lib/moonfire-nvr/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.7/src/server/server.rs:67:17' Backtrace: 0: failure::backtrace::internal::InternalBacktrace::new at .cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.8/src/backtrace/internal.rs:46:44 1: failure::backtrace::Backtrace::new at .cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.8/src/backtrace/mod.rs:121:35

::default at .cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.8/src/backtrace/mod.rs:140:13 2: moonfire_nvr::panic_hook at src/server/src/main.rs:91:13 core::ops::function::Fn::call at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/ops/function.rs:70:5 3: std::panicking::rust_panic_with_hook at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:595:17 4: std::panicking::begin_panic_handler::{{closure}} at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:497:13 5: std::sys_common::backtrace::__rust_end_short_backtrace at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/sys_common/backtrace.rs:141:18 6: rust_begin_unwind at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:493:5 7: std::panicking::begin_panic_fmt at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:435:5 8: hyper::server::server::Server::bind::{{closure}} at .cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.7/src/server/server.rs:67:17 9: core::result::Result::unwrap_or_else at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/result.rs:821:23 hyper::server::server::Server::bind at .cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.7/src/server/server.rs:66:28 10: moonfire_nvr::cmds::run::async_run::{{closure}} at src/server/src/cmds/run.rs:306:18 11: as core::future::future::Future>::poll at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/future/mod.rs:80:19 tokio::park::thread::CachedParkThread::block_on::{{closure}} at .cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.6.0/src/park/thread.rs:263:54 tokio::coop::with_budget::{{closure}} at .cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.6.0/src/coop.rs:106:9 std::thread::local::LocalKey::try_with at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/thread/local.rs:376:16 std::thread::local::LocalKey::with at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/thread/local.rs:352:9 12: tokio::coop::with_budget at .cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.6.0/src/coop.rs:99:5 tokio::coop::budget at .cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.6.0/src/coop.rs:76:5 tokio::park::thread::CachedParkThread::block_on at .cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.6.0/src/park/thread.rs:263:31 13: tokio::runtime::enter::Enter::block_on at .cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.6.0/src/runtime/enter.rs:151:13 tokio::runtime::thread_pool::ThreadPool::block_on at .cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.6.0/src/runtime/thread_pool/mod.rs:71:9 14: tokio::runtime::Runtime::block_on at .cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.6.0/src/runtime/mod.rs:452:43 15: moonfire_nvr::cmds::run::run at src/server/src/cmds/run.rs:176:5 16: moonfire_nvr::Args::run at src/server/src/main.rs:68:33 moonfire_nvr::main at src/server/src/main.rs:141:9 17: core::ops::function::FnOnce::call_once at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/ops/function.rs:227:5 std::sys_common::backtrace::__rust_begin_short_backtrace at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/sys_common/backtrace.rs:125:18 18: std::rt::lang_start::{{closure}} at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/rt.rs:49:18 19: core::ops::function::impls:: for &F>::call_once at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/ops/function.rs:259:13 std::panicking::try::do_call at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:379:40 std::panicking::try at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:343:19 std::panic::catch_unwind at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panic.rs:431:14 std::rt::lang_start_internal at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/rt.rs:34:21 20: main 21: __libc_start_main 22: _start ``` **Camera (please complete the following information):** - Camera manufacturer and model: Lorex LNE8964AB - Firmware version: Unknown ``` Device TypeLNE8964AB System Version00022 Build Date2018-11-05 WEB VersionV3.2.1.582554 ONVIF Version16.12(V2.4.3.574996) ``` **Desktop (please complete the following information):** - OS: Ubuntu 16.04 - Browser: firefox - Version: 90.0.2 **Additional context**
scottlamb commented 3 years ago

Thanks for the clear bug report with stack trace. From these lines:

   8: hyper::server::server::Server<hyper::server::tcp::AddrIncoming,()>::bind::{{closure}}
             at .cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.7/src/server/server.rs:67:17

I believe the problem is that it can't bind the HTTP server because the address is unavailable. It defaults to 0.0.0.0:8080, and if you run eg sudo netstat --listening --tcp --program you'll find that some other program has claimed port 8080. You can stop the other thing or tell Moonfire NVR to use a different port via the --http-addr argument.

Moonfire NVR is giving a terrible error message. First of all, hyper is panicking with an error message:

panic!("error binding to {}: {}", addr, e);

and we appear to be swallowing that text. But anyway panics are supposed to be just for bugs, so we should be using try_bind instead of bind.

I'm marking this as a usability bug.

cholcombe973 commented 3 years ago

Thanks for digging into this! Yes that makes sense. I have a few other docker containers running on here. I'll remap the port. I was planning on digging into the code but you beat me to it 🙂. I'm looking forward to getting this working. This is a really useful project!