[Question] [HW4] How do SendError and RecvError occur at the same time?
kowonhyeok opened this issue · 6 comments
I tested my HW4(BoC) code(maybe problematic) by this simple test with --nocapture:
let (finish_sender, finish_receiver) = crossbeam_channel::bounded(0);
when!(;; {
println!("b1 start");
finish_sender.send(()).unwrap();
});
finish_receiver.recv().unwrap();
But below errors are occured:
running 1 test
b1 start
thread 'thread 'boc::boc<unnamed>' panicked at ' panicked at src\boc.rssrc\boc.rs::408404::2832:
:
called `Result::unwrap()` on an `Err` value: RecvErrorcalled `Result::unwrap()` on an `Err` value: "SendError(..)"
As far as I know, SendError and RecvError occured when sender or receiver is disconnected. But how do both errors occur at the same time?
I make thunk like this in Behavior::new():
thunk: unsafe { Box::new(move || f(cowns.get_mut())) },
And use like this in resolve_one:
let behavior = Box::from_raw(this.cast_mut());
rayon::spawn(move || {
(behavior.thunk)();
});
It looks strange to me, too. Does the same thing happen in the provided testcases (e.g. by running grade-boc.sh
)?
By running, grade-boc.sh
, this error occured in both basic test and stress test:
error: test failed, to rerun pass `--test boc`
Caused by:
process didn't exit successfully: `C:\Users\KoWH\cs431\homework\target\debug\deps\boc-ce57516ad9d8cba7.exe basic_test` (exit
code: 0xc0000005, STATUS_ACCESS_VIOLATION)
note: test exited abnormally; to see the full output pass --nocapture to the harness.
Test failed: cargo test --test boc basic_test
I found STATUS_HEAP_CORRUPTION
error occurs immediately after the end of one Behaviour. But I don't know why.
I am having the exact same problem. Getting errors like this, and every time a different one.
@kowonhyeok @SaschaBergsma STATUS_ACCESS_VIOLATION
and STATUS_HEAP_CORRUPTION
both tell you that your code has some memory access bugs. I can now guess that you are having such strange errors that SendError and RecvError happen simultaneously since you're corrupting the memory space internally used by crossbeam_channel
. I advise you to carefully look at your code if there are any mistakes when storing and accessing the raw pointers.
Thank you! I found my problem is caused by lifetime of Behavior
object. This is very helpful: #905.