Closed TaeHagen closed 1 month ago
Hi, firstly, is it open source such that I can reproduce it? If not, here are some suggestions to debug it on your own:
DartAttachment
's sse_decode function (usually in frb_generated.rs).In addition, if the app is not open sourceable, maybe you can just copy-paste the relavent parts (and remember to remove any sensitive information) and paste it here.
Btw, have you run codegen and ensure to use both the latest generated code on Dart and Rust side? My first guess is that the auto-generated routing logic somehow fails, e.g. on Dart side you put thing A with label 100, but on Rust side the label 100 somehow is understood as thing B.
Indeed the debugging strategy is very simple: Just follow the flow of a method call and see what is going on, and usually there will be a place when the expected behavior is different from actual behavior. There is no magic hidden somewhere, since everything is explicitly generated as plain Rust/Dart code, and you can add whatever printing/debugging/... code to it.
Thank you for the timely advice! The entire app is not ready to be open sourced so you won't be able to build it, but you can see the problematic file here: https://github.com/TaeHagen/bluebubbles-app/blob/rustpush/rust/src/api/api.rs
A big part of my problem has been lack of debugging tools. I am 100% sure the codegen was updated, as I tried many times. If you have any advice for debugging tools (note this problem only happens when I build for linux) it could be very helpful.
I'd like to debug pde_ffi_dispatcher_primary_impl
and see why it is calling DartAttachment
because that should be unrelated for the method I am calling (get_user_name
). However, when I try to add a log (see below) nothing ends up printed. Am I adding it in the wrong spot?
Thank you!
A big part of my problem has been lack of debugging tools.
I personally just print here and there, and it is usually sufficient (at least in this specific case).
nothing ends up printed.
Maybe try log::error!(...)
, and it will print if the default hook is setup (which is true for auto-generated templates)
Btw, try to run in debug (not release) mode to see the line numbers and maybe some more sanity checks
I am running in debug mode. I tried log::error, nothing still is printed. I think I might be adding it in wrong spot?
Also I know macros are helpful, but in this case I think pde_ffi_dispatcher_primary_impl
is called by a macro, so I'm not sure where to go from here.
I also considered building with ASAN, but not sure how to get flutter_rust_bridge to build with rust nightly
I also considered building with ASAN, but not sure how to get flutter_rust_bridge to build with rust nightly
I guess it may be a more normal problem than memory issues at first glance since you are using SSE codec. But in case you are interested, have a look at ci.yaml, where flutter_rust_bridge has full tests running using ASAN and Valgrind.
I am running in debug mode. I tried log::error, nothing still is printed. I think I might be adding it in wrong spot?
Maybe try to firstly log it in a good function to see whether the logs are shown.
EDIT: Seems that you are using https://github.com/TaeHagen/bluebubbles-app/blob/03a40bcfd0e35c37a496e3adaff9ab967b2c5ce5/rust/src/api/api.rs#L49 for logging setup. Maybe copy-paste https://github.com/fzyzcjy/flutter_rust_bridge/blob/57e96640af6138f278ace64133b5ac680c746935/frb_example/dart_minimal/rust/src/api/minimal.rs#L3-L6 to let it auto called at startup to setup logging to terminal.
In addition, it would be great to provide a compilable project (maybe just remove all your real logic by things like unimplemented!()
and throw Exception()
), then I can directly look at it!
Thank you! Also do you have any ideas why it would work fine on Android, but panic on Linux?
You are welcome!
Also do you have any ideas why it would work fine on Android, but panic on Linux?
Hmm good question! Indeed it can be anything, yes including memory issues you mentioned, or other things like platform specific code, or different ABI, etc. Anyway, providing a compilable project will help a lot.
Also I know macros are helpful, but in this case I think pde_ffi_dispatcher_primary_impl is called by a macro, so I'm not sure where to go from here.
Forgot to reply this... One way is to expand that macro to see real code (IDE has this feature; or use cargo expand or whatever), and then just remove the original macro call and paste the real code there. Then can add whatever logs.
I've been working around this for the past few days, but seems like the plague has spread to android too. It comes in multiple variants, one is: (the size differs)
This appears to be triggered after i add a method. I will add a new method, rebuild, and then this crap will start happening
Wait, that one might have been caused by me hot reloading and not deploying... oops.
Wait, that one might have been caused by me hot reloading and not deploying... oops.
Yes, Rust requires recompiling currently...
As for this specific point, maybe we can make a very simple check: e.g. generate a dart const and a rust const (random number, content hash, etc), and when RustLib.init, ensure the two consts agree with each other.
I've been working around this for the past few days
Sorry to hear that :/ Personally speaking this may not be super hard to spot at least the shallow cause... Just follow the flow of data and see which exact part goes wrong (e.g. suppose the byte array is good at Dart side but bad at Rust side, then we know it is the FFI; suppose it is already bad at Dart side, then we know it is serialization problem, etc.) In addition, since you have already open sourced the bridge-related code, maybe is it possible to remove all real business logic and provide a compilable demo, such that I can have a look at it.
For me, it's mostly a debugging issue, and not a huge blocker for now (can just use android). Also, I recently re-pulled my repo, so hopefully it fixes itself? / was a build artifact?
I see. Feel free to ping me when need help / the problem re-occurs / it is open sourced (thus have compilable reproducible sample)!
was a build artifact?
That looks also quite possible: Many function ids change if you add one new function. And if you have new Dart code + old Rust code (e.g. forget to recompile the whole project, but only use a hot restart), that will make it call the wrong Rust function wrapper. Then, the wrong Rust function wrapper will decode the binary message (if using SSE codec) into the wrong struct type, then the error occurs. (since there is no reproducible sample, all my words are only guesses)
https://github.com/fzyzcjy/flutter_rust_bridge/pull/1878 will ensure code are in-sync.
I re-built everything from scratch (pulled git repo in diff folder, actually funny story accidentally rm -rf /'d my working tree, wasn't that bad tho).
It's working now. I think it was some weird build cache thing. I'll leave this up to you if you want to investigate further.
Thank you for all your work!
You are welcome and happy to see it working! After #1878 is released, you can try latest version, and see whether the sanity check directly fails if one day the bug re-appears.
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.
Describe the bug
When adding a new function and building the bridge, the function in the file panics in rust when called. It works on android, panics on linux. I don't even know why
DartAttachment
was being deserialized in the backtrace, it should have nothing to do with this call at all. If I add it at certain points it will make the next function fail too. I think there might be a memory corruption vuln somewhere.The function I added is:
pub async fn get_user_name(state: &Arc<PushState>) -> anyhow::Result<String> { let inner = state.0.read().await; let (first, last) = inner.account.as_ref().unwrap().get_name(); Ok(format!("{first} {last}")) }
Steps to reproduce
Honestly no clue how what the conditions are, this is almost an ask for (what the hell is going on?)
Logs
Expected behavior
The function should call and work like normal. An unrelated function should not stop working when I add a completely different function
Generated binding code
No response
OS
Linux
Version of
flutter_rust_bridge_codegen
2.0.0-dev.28
Flutter info
Version of
clang++
14.0.0-1ubuntu1.1
Additional context
Running for linux