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

Session is not tied by lifetime to the environment => easy segfaults #42

Closed
aldanor opened this issue Nov 29, 2020 · 1 comment · Fixed by #46
Closed

Session is not tied by lifetime to the environment => easy segfaults #42

aldanor opened this issue Nov 29, 2020 · 1 comment · Fixed by #46
Labels
bug Something isn't working

Comments

@aldanor
Copy link

aldanor commented Nov 29, 2020

The crate is meant to be safe, but here's one super easy way to segfault it.

Instead of writing

let environment = Environment::builder()
    .build()?;
let mut session = environment
    .new_session_builder()?
    .with_model_from_file("squeezenet1.0-8.onnx")?;
// session.run()

write this

let mut session = Environment::builder()
    .build()?
    .new_session_builder()?
    .with_model_from_file("squeezenet1.0-8.onnx")?;
// session.run() <--- segfault

It's not immediately unclear that you're doing something evil here in the safe code, and it compiles just fine - and then segfaults.

@nbigaouette
Copy link
Owner

Thanks for reporting!

I can confirm this issue on 32e9935.

It's weird because Environment::new_session_builder() will clone self to pass to the new session:
https://github.com/nbigaouette/onnxruntime-rs/blob/32e9935a8b30cffda3a92f458fb7f2db/onnxruntime/src/environment.rs#L138

An environment is a wrapper over the singleton:
https://github.com/nbigaouette/onnxruntime-rs/blob/32e9935a8b30cffda3a92f458fb7f2db/onnxruntime/src/environment.rs#L61-L63

This was done to have a single environment per process. This was done because the environment was not (completely) threadsafe: having a logging manager would break the safety. See #18. Since the PR was merged an released, I could revisit how environment and sessions are created, fixing #38 at the same time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants