rust-lang / backtrace-rs

Backtraces in Rust
https://docs.rs/backtrace
Other
530 stars 245 forks source link

make users able to set backtrace limit #454

Closed name1e5s closed 2 years ago

name1e5s commented 2 years ago

Recently I found a bug on android when I was attemping to capture stack backtrace in a rust function called by Android app through JNI. The _Unwind_Backtrace called our callback to push the Frames into a Vec with the same address(art_quick_generic_jni_trampoline + 42) over and over again, and finally makes my device out of memory and have to kill the Android App to save the whole system. I think it's better to provide a api to make developers able to set the backtrace limit by themself, even when the backtrace is captured by third-party crates.

Anyone can reproduce the problem using the following demo using an arm/aarch64 device with android 7.0 ~ android 12: https://github.com/name1e5s/backtrace_oom_demo

alexcrichton commented 2 years ago

I think it might be good to fix the bug on android where an infinite backtrace is returned, but I don't think that this particular solution belongs in this crate. The callback already returns a bool to stop the traceback and that enables users to already limit their backtrace, so I don't think there's any need to introduce secret mutable state for this.