Skip to content
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

[Question] [HW4] How do SendError and RecvError occur at the same time? #925

Closed
kowonhyeok opened this issue Apr 20, 2024 · 6 comments
Closed
Assignees
Labels
homework - boc boc.rs question Further information is requested

Comments

@kowonhyeok
Copy link

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)();
});
@kowonhyeok kowonhyeok added the question Further information is requested label Apr 20, 2024
@kingdoctor123
Copy link
Member

It looks strange to me, too. Does the same thing happen in the provided testcases (e.g. by running grade-boc.sh)?

@kowonhyeok
Copy link
Author

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

@kowonhyeok
Copy link
Author

I found STATUS_HEAP_CORRUPTION error occurs immediately after the end of one Behaviour. But I don't know why.

@SaschaBergsma
Copy link

I am having the exact same problem. Getting errors like this, and every time a different one.

@kingdoctor123
Copy link
Member

@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.

@kowonhyeok
Copy link
Author

Thank you! I found my problem is caused by lifetime of Behavior object. This is very helpful: #905.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
homework - boc boc.rs question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants