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

IPv6 & IPv4 use same port crash. #6259

Closed
dryBranch opened this issue Jan 1, 2024 · 2 comments
Closed

IPv6 & IPv4 use same port crash. #6259

dryBranch opened this issue Jan 1, 2024 · 2 comments
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-net Module: tokio/net

Comments

@dryBranch
Copy link

Version
pi@raspbian:~/workspace/rust/tokio_2stack$ cargo tree | rg tokio
tokio_2stack v0.1.0 (/home/pi/workspace/rust/tokio_2stack)
└── tokio v1.35.1
└── tokio-macros v2.2.0 (proc-macro)

Platform
pi@raspbian:~/workspace/rust/tokio_2stack$ uname -a
Linux raspbian 5.10.78-Release-OPENFANS+20211111-v8 #1 SMP PREEMPT Thu Nov 11 15:43:52 CST 2021 aarch64 GNU/Linux

Description
use IPv6 [::] and IPv4 0.0.0.0 and use same port(eg.21000) crash in my raspberry pi4.

  • It's OK in Windows10 x64.
  • It's OK use [::1] & 127.0.0.1
  • It's OK use [::] alone.

[short summary of the bug]

I tried this code:

use tokio::net::TcpListener;

#[tokio::main]
async fn main() {
    tokio::spawn(async {
        let addr = "[::]:21000";
        let l2 = TcpListener::bind(addr).await.unwrap();
        println!("listen {addr}");
        while let Ok((_stream, _addr)) = l2.accept().await {

        }
    });

    let addr = "0.0.0.0:21000";
    let l1 = TcpListener::bind(addr).await.unwrap();
    println!("listen {addr}");
    while let Ok((_stream, _addr)) = l1.accept().await {

    }
}

[code sample that causes the bug]

I expected to see this happen: [explanation]
Windows Env outputs

$ cargo r
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target\debug\tokio_2stack.exe`
listen 0.0.0.0:21000
listen [::]:21000

Instead, this happened: [explanation]

pi@raspbian:~/workspace/rust/tokio_2stack/src$ cargo r
   Compiling tokio_2stack v0.1.0 (/home/pi/workspace/rust/tokio_2stack)
    Finished dev [unoptimized + debuginfo] target(s) in 10.00s
     Running `/home/pi/workspace/rust/tokio_2stack/target/debug/tokio_2stack`
listen 0.0.0.0:21000
thread 'tokio-runtime-worker' panicked at src/main.rs:7:48:
called `Result::unwrap()` on an `Err` value: Os { code: 98, kind: AddrInUse, message: "Address already in use" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
^C

Additional Backtrace

pi@raspbian:~/workspace/rust/tokio_2stack$ RUST_BACKTRACE=full cargo r
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s
     Running `target/debug/tokio_2stack`
listen 0.0.0.0:21000
thread 'tokio-runtime-worker' panicked at src/main.rs:7:48:
called `Result::unwrap()` on an `Err` value: Os { code: 98, kind: AddrInUse, message: "Address already in use" }
stack backtrace:
   0:     0xaaaad2df89f0 - std::backtrace_rs::backtrace::libunwind::trace::heaab0e590535aeb3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0xaaaad2df89f0 - std::backtrace_rs::backtrace::trace_unsynchronized::h89cc7ae9ebb707d7
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0xaaaad2df89f0 - std::sys_common::backtrace::_print_fmt::h08c31be18fedf422
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:67:5
   3:     0xaaaad2df89f0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc38bcf44d9e857e3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:44:22
   4:     0xaaaad2e17374 - core::fmt::rt::Argument::fmt::ha5b752f9cd7ef4a3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/rt.rs:138:9
   5:     0xaaaad2e17374 - core::fmt::write::h9fac187ae7486f3c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/mod.rs:1094:21
   6:     0xaaaad2df5c3c - std::io::Write::write_fmt::h239e9fb6296b3a7f
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/io/mod.rs:1714:15
   7:     0xaaaad2df8824 - std::sys_common::backtrace::_print::h52f67cfa8753b0ab
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:47:5
   8:     0xaaaad2df8824 - std::sys_common::backtrace::print::hdea7481e2c957a93
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:34:9
   9:     0xaaaad2df9ea8 - std::panicking::default_hook::{{closure}}::h7c36fa733369c49e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:270:22
  10:     0xaaaad2df9bd0 - std::panicking::default_hook::h303eee75f9a8f6a8
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:290:9
  11:     0xaaaad2dfa46c - std::panicking::rust_panic_with_hook::h270c94381ec34744
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:707:13
  12:     0xaaaad2dfa334 - std::panicking::begin_panic_handler::{{closure}}::h3653e3502bcc1625
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:599:13
  13:     0xaaaad2df8ed4 - std::sys_common::backtrace::__rust_end_short_backtrace::h6b8510f2f024eeeb
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:170:18
  14:     0xaaaad2dfa084 - rust_begin_unwind
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
  15:     0xaaaad2d10124 - core::panicking::panic_fmt::ha96945d7a1b20293
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
  16:     0xaaaad2d10464 - core::result::unwrap_failed::h52241e4ea1d20f58
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/result.rs:1652:5
  17:     0xaaaad2d21ad0 - core::result::Result<T,E>::unwrap::hf7ab69f9b7f963be
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/result.rs:1077:23
  18:     0xaaaad2d24b00 - tokio_2stack::main::{{closure}}::{{closure}}::h4403a590f2067d48
                               at /home/pi/workspace/rust/tokio_2stack/src/main.rs:7:18
  19:     0xaaaad2d176b0 - tokio::runtime::task::core::Core<T,S>::poll::{{closure}}::h8790ea443f649480
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/core.rs:328:17
  20:     0xaaaad2d17020 - tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut::h080b1e6b9e35d658
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/loom/std/unsafe_cell.rs:16:9
  21:     0xaaaad2d17020 - tokio::runtime::task::core::Core<T,S>::poll::hbb294aefaea13a64
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/core.rs:317:13
  22:     0xaaaad2d1b1e0 - tokio::runtime::task::harness::poll_future::{{closure}}::h9e6ea0ce96271cea
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/harness.rs:485:19
  23:     0xaaaad2d2436c - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hf6110c1353675bb8
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panic/unwind_safe.rs:271:9
  24:     0xaaaad2d12060 - std::panicking::try::do_call::h0523503e7fbb6c6d
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:502:40
  25:     0xaaaad2d130a8 - __rust_try
  26:     0xaaaad2d11cc4 - std::panicking::try::h9cc7b7c3383887db
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:466:19
  27:     0xaaaad2d1d958 - std::panic::catch_unwind::h42a3b00ba2d3e8aa
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panic.rs:142:14
  28:     0xaaaad2d1ad8c - tokio::runtime::task::harness::poll_future::hcbaae4f41a769d16
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/harness.rs:473:18
  29:     0xaaaad2d1b924 - tokio::runtime::task::harness::Harness<T,S>::poll_inner::ha934b0f3aa8d2643
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/harness.rs:208:27
  30:     0xaaaad2d1c350 - tokio::runtime::task::harness::Harness<T,S>::poll::ha850989941c941be
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/harness.rs:153:15
  31:     0xaaaad2d190a4 - tokio::runtime::task::raw::poll::h10007068c25a1f5c
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/raw.rs:271:5
  32:     0xaaaad2d3fe98 - tokio::runtime::task::raw::RawTask::poll::h94abebad479cec85
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/raw.rs:201:18
  33:     0xaaaad2d726ec - tokio::runtime::task::LocalNotified<S>::run::hc3c6a90431df3e05
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/mod.rs:416:9
  34:     0xaaaad2d7cf5c - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::{{closure}}::h24f53b56649a7486
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/scheduler/multi_thread/worker.rs:576:13
  35:     0xaaaad2d7ce3c - tokio::runtime::coop::with_budget::he30a48da86c58214
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/coop.rs:107:5
  36:     0xaaaad2d7ce3c - tokio::runtime::coop::budget::h163cfc5a00aafd9e
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/coop.rs:73:5
  37:     0xaaaad2d7ce3c - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::h12711c6b2fbb41c5
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/scheduler/multi_thread/worker.rs:575:9
  38:     0xaaaad2d7c64c - tokio::runtime::scheduler::multi_thread::worker::Context::run::ha147f7917a662a0f
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/scheduler/multi_thread/worker.rs:526:24
  39:     0xaaaad2d7c1f0 - tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}::{{closure}}::h56eabd6fe4c2af51
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/scheduler/multi_thread/worker.rs:491:21
  40:     0xaaaad2d458c8 - tokio::runtime::context::scoped::Scoped<T>::set::he903eaae73015dd3
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/context/scoped.rs:40:9
  41:     0xaaaad2d4dd54 - tokio::runtime::context::set_scheduler::{{closure}}::h7124cad13c4031b5
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/context.rs:176:26
  42:     0xaaaad2d830a8 - std::thread::local::LocalKey<T>::try_with::hca400d953654a7f2
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/local.rs:270:16
  43:     0xaaaad2d813e8 - std::thread::local::LocalKey<T>::with::hae5084252d3ee0b1
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/local.rs:246:9
  44:     0xaaaad2d4dce8 - tokio::runtime::context::set_scheduler::heae8a5da85a5e339
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/context.rs:176:9
  45:     0xaaaad2d7c114 - tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}::h464d1e14f16a312c
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/scheduler/multi_thread/worker.rs:486:9
  46:     0xaaaad2d672c4 - tokio::runtime::context::runtime::enter_runtime::h76cabbd2be596576
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/context/runtime.rs:65:16
  47:     0xaaaad2d7bf4c - tokio::runtime::scheduler::multi_thread::worker::run::hbc685fba6f2f70c0
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/scheduler/multi_thread/worker.rs:478:5
  48:     0xaaaad2d7bdd4 - tokio::runtime::scheduler::multi_thread::worker::Launch::launch::{{closure}}::h0c1ac7fe889df93b
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/scheduler/multi_thread/worker.rs:447:45
  49:     0xaaaad2d355f0 - <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll::hfecebfd77beec6d0
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/blocking/task.rs:42:21
  50:     0xaaaad2d3a474 - tokio::runtime::task::core::Core<T,S>::poll::{{closure}}::h5151f2dab1c2c86c
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/core.rs:328:17
  51:     0xaaaad2d39e18 - tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut::h46377ce467f9eaa7
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/loom/std/unsafe_cell.rs:16:9
  52:     0xaaaad2d39e18 - tokio::runtime::task::core::Core<T,S>::poll::h49617d49e1797c85
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/core.rs:317:13
  53:     0xaaaad2d64764 - tokio::runtime::task::harness::poll_future::{{closure}}::h5072a5ae0e6597a4
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/harness.rs:485:19
  54:     0xaaaad2d80d88 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hd2aafcb36572629b
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panic/unwind_safe.rs:271:9
  55:     0xaaaad2d905e0 - std::panicking::try::do_call::hcc950c2086d2a32d
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:502:40
  56:     0xaaaad2d922f0 - __rust_try
  57:     0xaaaad2d8f7b8 - std::panicking::try::h5ca9375d9a55477c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:466:19
  58:     0xaaaad2d38188 - std::panic::catch_unwind::h133f76910dca4fd3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panic.rs:142:14
  59:     0xaaaad2d63ed0 - tokio::runtime::task::harness::poll_future::h05601e379f29e00b
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/harness.rs:473:18
  60:     0xaaaad2d62404 - tokio::runtime::task::harness::Harness<T,S>::poll_inner::hbbc563d7384f7dc6
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/harness.rs:208:27
  61:     0xaaaad2d61ddc - tokio::runtime::task::harness::Harness<T,S>::poll::h2c703414b983c8cb
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/harness.rs:153:15
  62:     0xaaaad2d40198 - tokio::runtime::task::raw::poll::h337c8b258559b060
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/raw.rs:271:5
  63:     0xaaaad2d3fe98 - tokio::runtime::task::raw::RawTask::poll::h94abebad479cec85
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/raw.rs:201:18
  64:     0xaaaad2d727b0 - tokio::runtime::task::UnownedTask<S>::run::h39b3b498ca81f878
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/task/mod.rs:453:9
  65:     0xaaaad2d47f04 - tokio::runtime::blocking::pool::Task::run::h32289973690074c4
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/blocking/pool.rs:159:9
  66:     0xaaaad2d4a374 - tokio::runtime::blocking::pool::Inner::run::h5ca4e45cd6651c2a
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/blocking/pool.rs:513:17
  67:     0xaaaad2d4a124 - tokio::runtime::blocking::pool::Spawner::spawn_thread::{{closure}}::h67a3c264bbbd9aee
                               at /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.35.1/src/runtime/blocking/pool.rs:471:13
  68:     0xaaaad2d38128 - std::sys_common::backtrace::__rust_begin_short_backtrace::h12f45f20ae080dec
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:154:18
  69:     0xaaaad2d4b938 - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::h4533a8431dbee961
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:529:17
  70:     0xaaaad2d80cc4 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h8440b2e4f6a7c1a7
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panic/unwind_safe.rs:271:9
  71:     0xaaaad2d902f0 - std::panicking::try::do_call::h561a93878e3956b1
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:502:40
  72:     0xaaaad2d922f0 - __rust_try
  73:     0xaaaad2d8f658 - std::panicking::try::h4e93853bdc567305
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:466:19
  74:     0xaaaad2d4b7cc - std::panic::catch_unwind::hf95b06e5ec729be0
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panic.rs:142:14
  75:     0xaaaad2d4b7cc - std::thread::Builder::spawn_unchecked_::{{closure}}::h57625d34cf34f96d
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:528:30
  76:     0xaaaad2d2b664 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h8bfe8bc32013dcb6
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:250:5
  77:     0xaaaad2dfcaa4 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h01303c6de09f5469
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  78:     0xaaaad2dfcaa4 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4f39e7995f973f4c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  79:     0xaaaad2dfcaa4 - std::sys::unix::thread::Thread::new::thread_start::h9f792bc0c268271e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17
  80:     0xffffbb50c7e4 - start_thread
  81:     0xffffbb39159c - <unknown>
  82:                0x0 - <unknown>
^C
@dryBranch dryBranch added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Jan 1, 2024
@dryBranch
Copy link
Author

I check it with std, same result. Maybe it's a spec problem of raspberry pi.

use std::{thread, net::TcpListener};

fn main() {
    thread::spawn(|| {
        let addr = "[::]:21000";
        let l1 = TcpListener::bind(addr).unwrap();
        println!("listen {addr}");
        while let Ok(_) = l1.accept() { }
    });

    let addr = "0.0.0.0:21000";
    let l2 = TcpListener::bind(addr).unwrap();
    println!("listen {addr}");
    while let Ok(_) = l2.accept() { }
}

output

pi@raspbian:~/workspace/rust/std_2stack$ RUST_BACKTRACE=full cargo r
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/std_2stack`
listen 0.0.0.0:21000
thread '<unnamed>' panicked at src/main.rs:6:42:
called `Result::unwrap()` on an `Err` value: Os { code: 98, kind: AddrInUse, message: "Address already in use" }
stack backtrace:
   0:     0xaaaacfb9745c - std::backtrace_rs::backtrace::libunwind::trace::heaab0e590535aeb3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0xaaaacfb9745c - std::backtrace_rs::backtrace::trace_unsynchronized::h89cc7ae9ebb707d7
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0xaaaacfb9745c - std::sys_common::backtrace::_print_fmt::h08c31be18fedf422
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:67:5
   3:     0xaaaacfb9745c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc38bcf44d9e857e3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:44:22
   4:     0xaaaacfbb5590 - core::fmt::rt::Argument::fmt::ha5b752f9cd7ef4a3
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/rt.rs:138:9
   5:     0xaaaacfbb5590 - core::fmt::write::h9fac187ae7486f3c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/mod.rs:1094:21
   6:     0xaaaacfb94bec - std::io::Write::write_fmt::h239e9fb6296b3a7f
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/io/mod.rs:1714:15
   7:     0xaaaacfb97290 - std::sys_common::backtrace::_print::h52f67cfa8753b0ab
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:47:5
   8:     0xaaaacfb97290 - std::sys_common::backtrace::print::hdea7481e2c957a93
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:34:9
   9:     0xaaaacfb98914 - std::panicking::default_hook::{{closure}}::h7c36fa733369c49e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:270:22
  10:     0xaaaacfb9863c - std::panicking::default_hook::h303eee75f9a8f6a8
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:290:9
  11:     0xaaaacfb98ed8 - std::panicking::rust_panic_with_hook::h270c94381ec34744
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:707:13
  12:     0xaaaacfb98da0 - std::panicking::begin_panic_handler::{{closure}}::h3653e3502bcc1625
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:599:13
  13:     0xaaaacfb97940 - std::sys_common::backtrace::__rust_end_short_backtrace::h6b8510f2f024eeeb
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:170:18
  14:     0xaaaacfb98af0 - rust_begin_unwind
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
  15:     0xaaaacfb77b48 - core::panicking::panic_fmt::ha96945d7a1b20293
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
  16:     0xaaaacfb77df8 - core::result::unwrap_failed::h52241e4ea1d20f58
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/result.rs:1652:5
  17:     0xaaaacfb78970 - core::result::Result<T,E>::unwrap::h9d2314d6532c8147
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/result.rs:1077:23
  18:     0xaaaacfb781c4 - std_2stack::main::{{closure}}::h51b1b4cdf5bb3546
                               at /home/pi/workspace/rust/std_2stack/src/main.rs:6:18
  19:     0xaaaacfb7d62c - std::sys_common::backtrace::__rust_begin_short_backtrace::hb4c68872210fde64
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:154:18
  20:     0xaaaacfb7941c - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::h43d078fe3205bc73
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:529:17
  21:     0xaaaacfb7ac98 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h93cb94ccb1f01cbe
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panic/unwind_safe.rs:271:9
  22:     0xaaaacfb7a5c0 - std::panicking::try::do_call::hf08588a377ef1f93
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:502:40
  23:     0xaaaacfb7a708 - __rust_try
  24:     0xaaaacfb7a528 - std::panicking::try::h27af41256150c21e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:466:19
  25:     0xaaaacfb792dc - std::panic::catch_unwind::hd6591bdffec6a4a9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panic.rs:142:14
  26:     0xaaaacfb792dc - std::thread::Builder::spawn_unchecked_::{{closure}}::hefebfafc9a3e9d6b
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/mod.rs:528:30
  27:     0xaaaacfb7b724 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h3099d65634de8f49
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:250:5
  28:     0xaaaacfb9af64 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h01303c6de09f5469
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  29:     0xaaaacfb9af64 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4f39e7995f973f4c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  30:     0xaaaacfb9af64 - std::sys::unix::thread::Thread::new::thread_start::h9f792bc0c268271e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17
  31:     0xffffafc417e4 - start_thread
  32:     0xffffafb8359c - <unknown>
  33:                0x0 - <unknown>
^C

@Darksonn Darksonn added the M-net Module: tokio/net label Jan 1, 2024
@Darksonn
Copy link
Contributor

Darksonn commented Jan 1, 2024

That's just how it works on Linux. You can search for the IPV6_V6ONLY flag and /proc/sys/net/ipv6/bindv6only to learn more.

@Darksonn Darksonn closed this as not planned Won't fix, can't repro, duplicate, stale Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-net Module: tokio/net
Projects
None yet
Development

No branches or pull requests

2 participants