jamesmcm / vopono

Run applications through VPN tunnels with temporary network namespaces
GNU General Public License v3.0
886 stars 46 forks source link

Panic on ConnectionReset #206

Open mstaack opened 1 year ago

mstaack commented 1 year ago

once again thank you for this awesome tool.

sometimes when disconnecting from my service (which runs with vopono) i get:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" }', /github/home/.cargo/registry/src/github.com-1ecc6299db9ec823/basic_tcp_proxy-0.3.0/src/lib.rs:45:68

its just a notification, everything continues to work.

anyway to gracefully handle this error within vopono?

cheers max

jamesmcm commented 1 year ago

Thanks, do you mean it happens only when stop the service? Or when disconnecting and then reconnecting e.g. on the host machine - and if so, does it continue to work after that (if you re-connect?)

It seems we just need to actually handle the possible fill_buf() error here, rather than just assuming it'd return an empty buffer:

https://github.com/jamesmcm/basic_tcp_proxy/blob/e3adcff17b46ecd871ff7d6f785de987d4945272/src/lib.rs#L45-L51

                            let buffer = stream_forward.fill_buf().unwrap();
                            let length = buffer.len();
                            if buffer.is_empty() {
                                // Connection closed
                                debug!("Client closed connection");
                                return;
                            }
mstaack commented 1 year ago

when disconnecting and then reconnecting.... yeah it does seem to keep on runnin

mstaack commented 1 year ago

have you any quick fix to solve this? i now saw the thread really crashing and my service being unavailable:

vopono[3817]: thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" }', /github/home/.cargo/registry/src/github.com-1ecc6299db9ec823/basic_tcp_proxy-0.3.0/src/lib.rs:45:68

dont really have any rust experience, but cant we just check for an error beforehand? https://doc.rust-lang.org/std/io/trait.BufRead.html#tymethod.fill_buf

jamesmcm commented 1 year ago

Yeah, we can just handle the error, I'll take a look today. - it's weird that it makes it unavailable though since it should only be for that connection.

I.e. if you reconnect it should be a different thread spawned,

mstaack commented 1 year ago

great thanks! do you mind publishing a new release?

mstaack commented 1 year ago

@jamesmcm ah just noticed the release github actions did not run....

jamesmcm commented 1 year ago

Yeah, I will do but I need to update the dockerhub images.

Github auto-closed this, I'll re-open it until it's published on the AUR, etc.

jamesmcm commented 1 year ago

It's released now, hopefully it fixes the issue. At least now it will definitely close the thread when the connection dies instead of unwinding the stack.

dsully commented 1 year ago

I'm seeing this still on 0.10.6. Will try and get a full stack trace.

dsully commented 1 year ago
 5:     0x557f1fdd907f - core::fmt::write::h6d54cd7c9e155ec5
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/fmt/mod.rs:1094:21
 6:     0x557f1fda7171 - std::io::Write::write_fmt::h6a453a71c692f63b
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/io/mod.rs:1713:15
 7:     0x557f1fdabff5 - std::sys_common::backtrace::_print::h1cbaa8b42678f928
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys_common/backtrace.rs:47:5
 8:     0x557f1fdabff5 - std::sys_common::backtrace::print::h4ddf81241a51b337
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys_common/backtrace.rs:34:9
 9:     0x557f1fdad517 - std::panicking::default_hook::{{closure}}::hff91f1f484ade5cd
10:     0x557f1fdad304 - std::panicking::default_hook::h21f14afd59f7aef9
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:288:9
11:     0x557f1fdad9cc - std::panicking::rust_panic_with_hook::h45f66047b14c555c
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:705:13
12:     0x557f1fdad8c7 - std::panicking::begin_panic_handler::{{closure}}::h49d1a88ef0908eb4
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:597:13
13:     0x557f1fdac616 - std::sys_common::backtrace::__rust_end_short_backtrace::hccebf9e57f8cc425
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys_common/backtrace.rs:151:18
14:     0x557f1fdad612 - rust_begin_unwind
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:593:5
15:     0x557f1ec5e9d3 - core::panicking::panic_fmt::h54ec9d0e3180a83d
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/panicking.rs:67:14
16:     0x557f1ec5ef63 - core::result::unwrap_failed::h1cd730365d65235f
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/result.rs:1651:5
17:     0x557f1ecf656f - core::result::Result<T,E>::expect::h6bb3b5e9f1c17db8
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/result.rs:1033:23
18:     0x557f1ecf41e7 - basic_tcp_proxy::TcpProxy::new::{{closure}}::{{closure}}::hfa72d9462a804592
                             at /home/dsully/.cargo/registry/src/index.crates.io-6f17d22bba15001f/basic_tcp_proxy-0.3.1/src/lib.rs:55:29
19:     0x557f1ecf8701 - std::sys_common::backtrace::__rust_begin_short_backtrace::hf675972befe731d9
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys_common/backtrace.rs:135:18
20:     0x557f1ecfc1ee - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::h05398c873d306ee4
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/thread/mod.rs:529:17
21:     0x557f1ecf8692 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::he53a717fd4dd3a98
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/panic/unwind_safe.rs:271:9
22:     0x557f1ecfd6a2 - std::panicking::try::do_call::hd1c49637c6542594
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:500:40
23:     0x557f1ecfd90b - __rust_try
24:     0x557f1ecfd4f6 - std::panicking::try::h6bc32f04446e8a0c
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:464:19
25:     0x557f1ecfb87c - std::panic::catch_unwind::h81ffb96bbc740d1a
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panic.rs:142:14
26:     0x557f1ecfb87c - std::thread::Builder::spawn_unchecked_::{{closure}}::h3085f1c805f095e6
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/thread/mod.rs:528:30
27:     0x557f1ecf474f - core::ops::function::FnOnce::call_once{{vtable.shim}}::hcc35965381d64437
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/ops/function.rs:250:5
28:     0x557f1fdb4405 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he3e5dbdfabe0b668
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/boxed.rs:1985:9
29:     0x557f1fdb4405 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h246f7c7964633611
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/alloc/src/boxed.rs:1985:9
30:     0x557f1fdb4405 - std::sys::unix::thread::Thread::new::thread_start::hadf9e3501ff0df23
                             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys/unix/thread.rs:108:17
31:     0x7fec9c28f18a - <unknown>
32:     0x7fec9c31dbd0 - <unknown>
33:                0x0 - <unknown>