tokio-rs / loom

Concurrency permutation testing tool for Rust.
MIT License
2.13k stars 111 forks source link

Stack size of spawned threads is not configurable #309

Closed akonradi closed 1 year ago

akonradi commented 1 year ago

The stack size of spawned threads is determined by the call to generator::Gn::new in spawn_threads: https://github.com/tokio-rs/loom/blob/16e5e9a0e562cf754ced04ac1a82802b8e492178/src/rt/scheduler.rs#L142-L158. Since loom doesn't specify a stack size, the generator crate's default is used, which is ~1000~ 4096 bytes. This isn't enough for code with deeply nested function calls; the result there is a stack overflow.

The stack size should be configurable either via environment variables or as an argument when invoking loom::model.

akonradi commented 1 year ago

If this isn't controversial, I'm happy to work on the environment variable approach.

schreter commented 1 year ago

+1, we just ran into the same issue - the test was short a few tens of bytes. I also pinpointed it to the stack size and then found this issue.

BTW, it's not 4096B, but sizeof(usize) * 4096, i.e., 32KB on 64-bit platforms. Your test with 0x8000 (i.e., 32KB) is just above the limit.

As a starting point, I think env variable approach would be a sufficient one. But, there is in fact a method Builder::stack_size(). This is empty for now. Maybe you want to implement it as well to pass the size?