Skip to content

A large RUST_THREADS value causes an abort #8879

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

Closed
huonw opened this issue Aug 30, 2013 · 2 comments
Closed

A large RUST_THREADS value causes an abort #8879

huonw opened this issue Aug 30, 2013 · 2 comments
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@huonw
Copy link
Member

huonw commented Aug 30, 2013

$ cat hello-world.rs
fn main() { println("hello world"); }
$ rustc hello-world.rs
$ RUST_THREADS=254 hello-world
hello world
$ RUST_THREADS=255 hello-world
Aborted

Backtrace (this appears to change occasionally, as does the exact RUST_THREADS value at which the crash happens):

#0  0x00007ffff67541e5 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff6757398 in __GI_abort () at abort.c:90
#2  0x00007ffff7431da7 in uv__loop_init (loop=loop@entry=0x7ffff5412900, default_loop=default_loop@entry=0)
    at ../../../../src/libuv/src/unix/loop.c:75
#3  0x00007ffff742e97d in uv_loop_new () at ../../../../src/libuv/src/unix/core.c:249
#4  0x00007ffff77f8bf9 in rt::run_::_82e8c355ab8d949f::_0$x2e8$x2dpre ()
   from /home/huon/projects/test-rust/../../rust/x86_64-unknown-linux-gnu/stage2/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-6c65cf4b443341b1-0.8-pre.so
#5  0x00007ffff779b0ed in unstable::lang::start::_76d6c774aa357c7a::_0$x2e8$x2dpre ()
   from /home/huon/projects/test-rust/../../rust/x86_64-unknown-linux-gnu/stage2/lib/rustc/x86_64-unknown-linux-gnu/lib/libstd-6c65cf4b443341b1-0.8-pre.so
#6  0x0000000000400a7b in main ()

There's only one thread.

(RUST_THREADS=<large> rustc works too, but gives a less-nice backtrace.)

@alexcrichton
Copy link
Member

I'm not entirely sure that there's a whole lot we can do about this. I believe that the reason for this is that libuv opens a bunch of file descriptors (for communication and such), and then we create even more by making lots of async handles.

We might be able to reduce the number of async handles we make, but otherwise I think this is just an issue of raising the file descriptor limits.

I'm not closing this though, because I would like to investigate if we can reduce the number of file descriptors we force libuv to generate, this is just a hunch of mine.

@alexcrichton
Copy link
Member

OK, I looked a bit more into this. This all from OSX's point of view, the reality is probably different for other platforms.

For me, the maximum file descriptor limit is 256. I was able to create ~128 pipes (2 per syscall) and then pipe started failing. It also turns out that libuv starts up 5 file descriptors per loop. Each event loop looks like it has one "event file descriptor", one pair of pipes for a signal handler, and one pair of pipes for an async watcher. All of this initialization always happens, it's not configurable. What this means is that you can create ~50 threads, at this rate (at least on my system), which is we we get an abort after creating the 52nd thread.

With this information in mind, I don't think that there's really anything we can do to fix this. The best action we can take is to alert the libuv folks to see if they can optimize the number of file descriptors they make per loop. In reality, I think this just means that the file descriptor limits need to be raised if you want this many threads. I suppose the other thing we could do is fail a bit more gracefully, but again this is kinda up to libuv b/c the abort is happening inside of libuv, not inside of our code.

I'm closing this because I don't think that there's enough actionable here by us. It'd be nice if we could spawn a million threads, but rust is optimized for spawning millions of tasks, not threads.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 4, 2022
`needless_return` checks for macro expr in return stmts

closes rust-lang#8879

Macro expressions in returns were not checked by `needless_return`. The test added in [this commit](rust-lang/rust-clippy@6396a7a#diff-a869168cfafb7e6e5010feb76a16389d6c96d59e98113dee5c2b304a5160e43aR51-R55) seems to have regressed.

changelog: [`needless_return`] checks for macro exprs in return statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

2 participants