-
Notifications
You must be signed in to change notification settings - Fork 328
Better debugging support for runtime safety errors #1914
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
Comments
Firstly, I guess it would be great if we show stack traces (for both Dart and Rust) when that panic happens. Indeed for native code it works great; IIRC it is the limitation of Web that makes panic handling not very elegant. Btw, IIRC the panic may report full Rust stack trace. Could you please try to enable full stacktrace and see whether that provides you more info?
Possibly related: #1641 (cc @Desdaemon). Possibly related for overall issue: #1883 (It's on my radar but has not have enough time to think about it deeply) |
In lieu of a static solution which might take some time to develop (personally I'm also very interested in this area), being able to expand the stack trace back to the offending code should be a halfway decent solution. I don't know how to do this off the top of my head, but it might require some cooperation from flutter_rust_bridge as well. |
@fzyzcjy I'm not sure how to get more info. I saw in the docs the link to https://stackoverflow.com/questions/69593235/how-to-get-panic-information-i-e-stack-trace-with-catch-unwind, but it looks like this is implemented directly already. I have an unchanged init.rs:
In main.dart, I call |
More broadly, I think what I maybe actually want is a supported way to avoid the runtime safety errors in the first place. Any chance there are flags I can use, or FRB APIs that I can avoid, so there are no possible runtime borrow checker issues? |
Firstly cc @Desdaemon - who implemented the whole web part from scratch, and IIRC he has mentioned some limitations of web panics (do they still hold today / is there any workarounds?). |
If you always use |
That's helpful (And also challenging, because I am keeping mutable data in Rust.) Before, I had RustOpaque<std::sync::Mutex> everywhere, so I manually called my own For the static analysis, I inquired with the dart team: dart-lang/sdk#55657. |
Two additional notes:
Does something like this make sense? I have a Dart object I changed my |
I'm not sure how relevant this is to your situation, but FRB uses try_read and try_write which are the weakest assumptions possible about whether it is possible to acquire a lock. While try_write fails even if there is a single other active borrower (high contention) it's the only acquisition mode that makes sense for both async and sync functions. If you need reliable lock acquisition, you might want to use |
Is it possible to still use
|
Oh yeah I did have this issue before, I think it's that once you use one type as an auto-opaque type you can't also use it inside |
IIRC try tokio's Mutex.
That looks pretty reasonable (and we need to find out a solution)
This looks like a bug. A workaround is to avoid such scenario (e.g. always use auto or non-auto; or add a wrapper type To support it, I am not sure what is the best semantics: A naive solution will introduce two exactly same named dart types, causing a lot of conflicts. |
Spitballing a little, maybe FRB could generate more than one dart package to allow these conflicts to be resolved. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue. |
Is your feature request related to a problem? Please describe.
I'm facing errors like the following, and finding it challenging to trace back to the code or object that has the safety issue.
Describe the solution you'd like
Somehow, we need a way to increase the probability of statically catching these issues, a bit clearer guidelines on how to avoid them, and more runtime support to help find what callsites are responsible for issues. On static analysis, I'm not sure if there's a team around the dart analyzer, but maybe there's a collaboration possible around getting a linear type checker into it.
In particular there's this warning in the docs:
The issue I think I'm running into is in writing Dart code that uses that normal Rust code, figuring out what's safe or not. I'm not 100% sure, but it seems possible to have working Dart code (that freely stores and copies some data) get turned unsafe for example by changing the Rust side of a type from a translated struct to a RustAutoOpaque.
Describe alternatives you've considered
N/A
The text was updated successfully, but these errors were encountered: