Describe the bug
If you use trippy-core inside a process that has more than 1024 active file descriptors, it will crash because of the select() FD limit.
Currently, my workaround is to call trippy-core from a child process.
To Reproduce
Repo with minimal repro example: https://github.com/ifd3f/trippy-core-select-repro
Here's the main.rs:
use std::net::IpAddr;
use std::str::FromStr;
use trippy_core::Builder;
fn main() {
let _fds = make_a_bunch_of_fds();
// copied nearly verbatim from docs.rs example
let addr = IpAddr::from_str("1.1.1.1").unwrap();
Builder::new(addr)
.build()
.unwrap()
.run_with(|round| println!("{:?}", round))
.unwrap();
}
fn make_a_bunch_of_fds() -> Vec<std::fs::File> {
(0..1024)
.map(|_| std::fs::File::open("/dev/null").unwrap())
.collect()
}
Running it:
$ ulimit -n 4096 # increase file descriptor limit
$ sudo target/debug/trippy-repro
thread 'main' (1028146) panicked at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nix-0.29.0/src/sys/select.rs:24:5:
fd must be in the range 0..FD_SETSIZE
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
RUST_BACKTRACE=full output
thread 'main' (1025341) panicked at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nix-0.29.0/src/sys/select.rs:24:5:
fd must be in the range 0..FD_SETSIZE
stack backtrace:
0: 0x55fce9a21122 - std::backtrace_rs::backtrace::libunwind::trace::h650f3484750cac6f
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
1: 0x55fce9a21122 - std::backtrace_rs::backtrace::trace_unsynchronized::hee951f78e969ac04
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
2: 0x55fce9a21122 - std::sys::backtrace::_print_fmt::hb210b023f6e87be7
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/sys/backtrace.rs:74:9
3: 0x55fce9a21122 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hdadc7c28d26d7ce3
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/sys/backtrace.rs:44:26
4: 0x55fce9a3106a - core::fmt::rt::Argument::fmt::hca43ba1468fa0a13
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/core/src/fmt/rt.rs:152:76
5: 0x55fce9a3106a - core::fmt::write::h469843d235cc4241
6: 0x55fce99fe776 - std::io::default_write_fmt::h2cd531246bd479c8
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/io/mod.rs:639:11
7: 0x55fce99fe776 - std::io::Write::write_fmt::h384251ddb7f1467c
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/io/mod.rs:1994:13
8: 0x55fce9a06386 - std::sys::backtrace::BacktraceLock::print::hb91bd19c9b07a6b2
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/sys/backtrace.rs:47:9
9: 0x55fce9a06386 - std::panicking::default_hook::{{closure}}::hd9d92b9a46805102
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panicking.rs:292:27
10: 0x55fce9a061e6 - std::panicking::default_hook::hedb2be0819bbe276
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panicking.rs:319:9
11: 0x55fce9a065cb - std::panicking::panic_with_hook::h0fc23abecf35c6bd
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panicking.rs:825:13
12: 0x55fce9a0647a - std::panicking::panic_handler::{{closure}}::ha111c1a3ccf85d19
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panicking.rs:691:13
13: 0x55fce9a04479 - std::sys::backtrace::__rust_end_short_backtrace::h41d63216e1ba5fa4
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/sys/backtrace.rs:182:18
14: 0x55fce99f364d - __rustc[16f1505adc47261a]::rust_begin_unwind
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panicking.rs:689:5
15: 0x55fce9a354cc - core::panicking::panic_fmt::hc13412975f563dde
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/core/src/panicking.rs:80:14
16: 0x55fce99daa70 - nix::sys::select::assert_fd_valid::he29674bfd2207b64
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nix-0.29.0/src/sys/select.rs:24:5
17: 0x55fce99dac22 - nix::sys::select::FdSet::insert::ha2ed047dfaf0c7a9
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nix-0.29.0/src/sys/select.rs:45:9
18: 0x55fce9962f85 - <trippy_core::net::platform::unix::socket::SocketImpl as trippy_core::net::socket::Socket>::is_readable::h8d15b358ab9257ec
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/trippy-core-0.13.0/src/net/platform/unix.rs:392:18
19: 0x55fce9957f66 - trippy_core::net::channel::Channel<S>::recv_icmp_probe::h27218f1819b449e8
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/trippy-core-0.13.0/src/net/channel.rs:157:29
20: 0x55fce99601c2 - <trippy_core::net::channel::Channel<S> as trippy_core::net::Network>::recv_probe::hc7afd8543d482eb7
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/trippy-core-0.13.0/src/net/channel.rs:104:52
21: 0x55fce9942a16 - trippy_core::strategy::Strategy<F>::recv_response::hc2a168b13cf69719
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/trippy-core-0.13.0/src/strategy.rs:170:28
22: 0x55fce9944e51 - trippy_core::strategy::Strategy<F>::run::hfa8e1401fb41caab
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/trippy-core-0.13.0/src/strategy.rs:75:18
23: 0x55fce9948314 - trippy_core::tracer::inner::TracerInner::run_internal::h3074007815e2424b
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/trippy-core-0.13.0/src/tracer.rs:673:22
24: 0x55fce994872a - trippy_core::tracer::inner::TracerInner::run_with::hf0cf68f29103e742
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/trippy-core-0.13.0/src/tracer.rs:539:18
25: 0x55fce99413c5 - trippy_core::tracer::Tracer::run_with::hac391e8a1601d1e4
at /home/astrid/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/trippy-core-0.13.0/src/tracer.rs:166:20
26: 0x55fce9941026 - trippy_repro::main::h8157cbe3700fde1f
at /home/astrid/Documents/trippy-repro/src/main.rs:13:10
27: 0x55fce994698b - core::ops::function::FnOnce::call_once::hb8f50c2204c07488
at /nix/store/486lfx1h01kcdnfplwfgs9qn1gyv441y-rust-default-1.94.1/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
28: 0x55fce99472be - std::sys::backtrace::__rust_begin_short_backtrace::ha2ec14e8866b30c7
at /nix/store/486lfx1h01kcdnfplwfgs9qn1gyv441y-rust-default-1.94.1/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:166:18
29: 0x55fce9941211 - std::rt::lang_start::{{closure}}::h7349005625dedb0e
at /nix/store/486lfx1h01kcdnfplwfgs9qn1gyv441y-rust-default-1.94.1/lib/rustlib/src/rust/library/std/src/rt.rs:206:18
30: 0x55fce99ffda6 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h8efc7cb5100ba425
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/core/src/ops/function.rs:287:21
31: 0x55fce99ffda6 - std::panicking::catch_unwind::do_call::hd88510648a5228a9
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panicking.rs:581:40
32: 0x55fce99ffda6 - std::panicking::catch_unwind::h173471a751c46510
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panicking.rs:544:19
33: 0x55fce99ffda6 - std::panic::catch_unwind::hdc57eacbe554a86b
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panic.rs:359:14
34: 0x55fce99ffda6 - std::rt::lang_start_internal::{{closure}}::h9ab091ff07a457f7
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/rt.rs:175:24
35: 0x55fce99ffda6 - std::panicking::catch_unwind::do_call::h3ebf6a66f77c4aa3
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panicking.rs:581:40
36: 0x55fce99ffda6 - std::panicking::catch_unwind::h1b18fb35dcd25d34
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panicking.rs:544:19
37: 0x55fce99ffda6 - std::panic::catch_unwind::h7de96059216a6851
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/panic.rs:359:14
38: 0x55fce99ffda6 - std::rt::lang_start_internal::hc68d929ebd5f7eea
at /rustc/e408947bfd200af42db322daf0fadfe7e26d3bd1/library/std/src/rt.rs:171:5
39: 0x55fce99411f7 - std::rt::lang_start::h5f0cc7babff16014
at /nix/store/486lfx1h01kcdnfplwfgs9qn1gyv441y-rust-default-1.94.1/lib/rustlib/src/rust/library/std/src/rt.rs:205:5
40: 0x55fce994119e - main
41: 0x7fa29e4cc285 - __libc_start_call_main
42: 0x7fa29e4cc338 - __libc_start_main_alias_2
43: 0x55fce9940775 - _start
44: 0x0 - <unknown>
Expected behavior
It works and performs the traceroute instead of crashing.
Screenshots
N/A
Environment Info
- OS: Linux x86_64 (specifically NixOS)
- Trippy version: trippy-core v0.13.0
- Installation method: cargo
- Terminal / Console: not relevant
Additional context
My understanding of the reason it crashes is because the Unix SocketImpl uses select() rather than poll() or epoll(), which will not be happy if you give it a file descriptor with number over its strict limit of FD_SETSIZE=1024. The fix would probably be to change it to use epoll(), and I'd be happy to contribute a fix to make it do that.
Describe the bug
If you use trippy-core inside a process that has more than 1024 active file descriptors, it will crash because of the select() FD limit.
Currently, my workaround is to call trippy-core from a child process.
To Reproduce
Repo with minimal repro example: https://github.com/ifd3f/trippy-core-select-repro
Here's the main.rs:
Running it:
RUST_BACKTRACE=full output
Expected behavior
It works and performs the traceroute instead of crashing.
Screenshots
N/A
Environment Info
Additional context
My understanding of the reason it crashes is because the Unix SocketImpl uses
select()rather thanpoll()orepoll(), which will not be happy if you give it a file descriptor with number over its strict limit of FD_SETSIZE=1024. The fix would probably be to change it to use epoll(), and I'd be happy to contribute a fix to make it do that.