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

Test execution hangs if guards are used in multiple tests #322

Closed
rasviitanen opened this issue Mar 29, 2021 · 4 comments · Fixed by #326
Closed

Test execution hangs if guards are used in multiple tests #322

rasviitanen opened this issue Mar 29, 2021 · 4 comments · Fixed by #326

Comments

@rasviitanen
Copy link

rasviitanen commented Mar 29, 2021

Environment

How do you use Sentry?
sentry.io

Which SDK and version?
sentry-rust (0.22.0)

Toolchain:
stable-x86_64-pc-windows-msvc (default)
rustc 1.50.0 (cb75ad5db 2021-02-10)

Steps to Reproduce

  1. Define two tests that creates guards:
#[test]
fn test_a() {
    let _guard = sentry::init(sentry::ClientOptions {
        ..Default::default()
    });
}

#[test]
fn test_b() {
    let _guard = sentry::init(sentry::ClientOptions {
        ..Default::default()
    });
}
  1. Run cargo test
  2. Get output:
running 2 tests
test tests::test_a ... ok
test tests::test_b ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s 
  1. Test execution freezes and doesn't return
  2. Here is an example application to reproduce the problem: https://github.com/rasviitanen/sentry-bug

Running the tests individually works fine

Expected Result

The test execution should finish with exit 0.

Actual Result

running 2 tests
test observability::tests::test_a ... ok
test observability::tests::test_b ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 63 filtered out; finished in 0.03s 
<here it just freezes and you have to press ctrl+c to exit>

We didn't experience any issues with this in 0.19.0

@rasviitanen rasviitanen changed the title Test execution hangs if guards are used in separate tests Test execution hangs if guards are used in multiple tests Mar 29, 2021
@rasviitanen
Copy link
Author

rasviitanen commented Apr 20, 2021

I think I have tracked down the issue to these lines:

// note on safety: this is safe because even though we change the Arc
// by temorary binding we guarantee that the original Arc stays alive.
// For more information see: run
THREAD_HUB.with(|stack| unsafe {
let ptr = stack.get();
f(&*ptr)
})

I guess it's the handeling of the global statics (THREAD_HUB/PROCESS_HUB) that doesn't work correctly when initializing sentry on multiple threads. Using the PROCESS_HUB in both cases fixes the symptomps but is not a fix.


Here is another example of reproducing the bug:

fn main() {
    let _guard = sentry::init(sentry::ClientOptions {
        ..Default::default()
    });

    std::thread::spawn(|| {
        let _guard = sentry::init(sentry::ClientOptions {
            ..Default::default()
        });
    }).join();
}

@Swatinem
Copy link
Member

I think I have tracked this down to the Drop impl of our SessionFlusher which was implemented in #279.
It seems that the PROCESS_HUB holds on to a reference to the Client and thus to the SessionFlusher, which will never be dropped.

@Swatinem
Copy link
Member

Oh, I see you were also on Windows, and interestingly enough I was also tracking this down on Windows.

This seems to have been a manifestation of rust-lang/rust#74875 I guess since that matches the conclusion I came to in #326

@rasviitanen
Copy link
Author

@Swatinem Amazing work, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants