loom icon indicating copy to clipboard operation
loom copied to clipboard

loom internal bug: index out of bounds: the len is 4 but the index is 4

Open Sherlock-Holo opened this issue 2 years ago • 4 comments

this codes

use loom::model::Builder;
use loom::thread;

let mut builder = Builder::new();
builder.max_threads = 10;

builder.check(|| {
    let mut handles = vec![];

    handles.push(thread::spawn(move || {}));

    handles.push(thread::spawn(move || {}));

    handles.push(thread::spawn(move || {}));

    handles.push(thread::spawn(move || {}));

    for handle in handles {
        handle.join().unwrap();
    }
})

will panic with

running 1 test
thread 'test_try_receive' panicked at 'index out of bounds: the len is 4 but the index is 4', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/execution.rs:82:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test test_try_receive ... FAILED

failures:

failures:
    test_try_receive

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass '--test try_receive'

Sherlock-Holo avatar Sep 18 '21 06:09 Sherlock-Holo

Can you include the backtrace in the output?

Darksonn avatar Sep 18 '21 07:09 Darksonn

running 1 test
thread 'test_try_receive' panicked at 'index out of bounds: the len is 4 but the index is 4', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/execution.rs:82:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/panicking.rs:103:14
   2: core::panicking::panic_bounds_check
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/panicking.rs:79:5
   3: <usize as core::slice::index::SliceIndex<[T]>>::index_mut
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/slice/index.rs:190:14
   4: core::slice::index::<impl core::ops::index::IndexMut<I> for [T]>::index_mut
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/slice/index.rs:26:9
   5: core::array::<impl core::ops::index::IndexMut<I> for [T; N]>::index_mut
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/array/mod.rs:230:9
   6: <loom::rt::vv::VersionVec as core::ops::index::IndexMut<loom::rt::thread::Id>>::index_mut
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/vv.rs:94:9
   7: loom::rt::execution::Execution::new_thread
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/execution.rs:82:9
   8: loom::rt::spawn::{{closure}}
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/mod.rs:69:36
   9: loom::rt::scheduler::Scheduler::with_execution::{{closure}}
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/scheduler.rs:48:28
  10: scoped_tls::ScopedKey<T>::with
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:171:13
  11: loom::rt::scheduler::Scheduler::with_execution
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/scheduler.rs:48:9
  12: loom::rt::execution
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/mod.rs:138:5
  13: loom::rt::spawn
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/mod.rs:69:14
  14: loom::thread::spawn_internal
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/thread.rs:129:9
  15: loom::thread::spawn
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/thread.rs:114:5
  16: try_receive::test_try_receive::{{closure}}
             at ./tests/try_receive.rs:20:22
  17: loom::model::Builder::check::{{closure}}
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/model.rs:201:17
  18: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/ops/function.rs:227:5
  19: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/alloc/src/boxed.rs:1636:9
  20: loom::rt::scheduler::spawn_threads::{{closure}}::{{closure}}
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.5.1/src/rt/scheduler.rs:140:21
  21: generator::gen_impl::GeneratorImpl<A,T>::init_code::{{closure}}
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/generator-0.7.0/src/gen_impl.rs:348:21
  22: generator::stack::StackBox<F>::call_once
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/generator-0.7.0/src/stack/mod.rs:139:13
  23: generator::stack::Func::call_once
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/generator-0.7.0/src/stack/mod.rs:121:9
  24: generator::gen_impl::gen_init::{{closure}}
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/generator-0.7.0/src/gen_impl.rs:550:9
  25: core::ops::function::FnOnce::call_once
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/ops/function.rs:227:5
  26: std::panicking::try::do_call
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/std/src/panicking.rs:403:40
  27: __rust_try
  28: std::panicking::try
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/std/src/panicking.rs:367:19
  29: std::panic::catch_unwind
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/std/src/panic.rs:133:14
  30: generator::gen_impl::gen_init
             at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/generator-0.7.0/src/gen_impl.rs:564:25
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test test_try_receive ... FAILED

failures:

failures:
    test_try_receive

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s

error: test failed, to rerun pass '--test try_receive'

Sherlock-Holo avatar Sep 18 '21 07:09 Sherlock-Holo

I notice there is a comment This should be set as low as possible and must be less than MAX_THREADS.

but there is no check before run the closure. Probably add a check before run the closure, and panic!("the max threads is {}, builder max_threads is {}", MAX_THREADS, builder.max_threads) if builder.max_threads >= MAX_THREADS

Sherlock-Holo avatar Sep 18 '21 07:09 Sherlock-Holo

Adding an assert sounds like a good idea.

Darksonn avatar Sep 19 '21 08:09 Darksonn