From e9e0d8d212b288e4f9c624f3f969e14ab3eab924 Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Tue, 7 Apr 2026 06:01:07 +0400 Subject: [PATCH] fix: replace tracing-android with android_logger (no sharded_slab SIGSEGV) tracing_subscriber::registry() allocates a sharded_slab which causes SIGSEGV on Android 16 MTE devices during nativeInit. catch_unwind can't catch SIGSEGV (it's a signal, not a panic). Replace with android_logger (lightweight, no large allocations) + tracing-log bridge so tracing::info! macros still work via logcat. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/wzp-android/Cargo.toml | 5 +++-- crates/wzp-android/src/jni_bridge.rs | 27 ++++++++++----------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/crates/wzp-android/Cargo.toml b/crates/wzp-android/Cargo.toml index b43995a..61769f0 100644 --- a/crates/wzp-android/Cargo.toml +++ b/crates/wzp-android/Cargo.toml @@ -17,7 +17,6 @@ wzp-crypto = { workspace = true } wzp-transport = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } -tracing-subscriber = { workspace = true, features = ["env-filter"] } bytes = { workspace = true } serde = { workspace = true } serde_json = "1" @@ -28,7 +27,9 @@ libc = "0.2" jni = { version = "0.21", default-features = false } rand = { workspace = true } rustls = { version = "0.23", default-features = false, features = ["ring"] } -tracing-android = "0.2" +android_logger = "0.14" +log = "0.4" +tracing-log = "0.2" [build-dependencies] cc = "1" diff --git a/crates/wzp-android/src/jni_bridge.rs b/crates/wzp-android/src/jni_bridge.rs index 3ddc11e..d5f7485 100644 --- a/crates/wzp-android/src/jni_bridge.rs +++ b/crates/wzp-android/src/jni_bridge.rs @@ -35,24 +35,17 @@ static INIT_LOGGING: Once = Once::new(); /// Safe to call multiple times — only the first call takes effect. fn init_logging() { INIT_LOGGING.call_once(|| { - // Wrap in catch_unwind — sharded_slab allocation inside - // tracing_subscriber::registry() can crash on some Android - // devices if scudo malloc fails during early initialization. + // Use android_logger directly — tracing_subscriber::registry() allocates + // a sharded_slab which causes SIGSEGV on Android 16 MTE devices. + // android_logger is lightweight and doesn't trigger scudo crashes. let _ = std::panic::catch_unwind(|| { - use tracing_subscriber::layer::SubscriberExt; - use tracing_subscriber::util::SubscriberInitExt; - use tracing_subscriber::EnvFilter; - if let Ok(layer) = tracing_android::layer("wzp_android") { - // Filter: INFO for our crates, WARN for everything else. - // The jni crate emits VERBOSE logs for every method lookup - // (~10 lines per JNI call, 100+ calls/sec) which floods logcat - // and causes the system to kill the app. - let filter = EnvFilter::new("warn,wzp_android=info,wzp_proto=info,wzp_transport=info,wzp_codec=info,wzp_fec=info,wzp_crypto=info"); - let _ = tracing_subscriber::registry() - .with(layer) - .with(filter) - .try_init(); - } + android_logger::init_once( + android_logger::Config::default() + .with_max_level(log::LevelFilter::Info) + .with_tag("wzp"), + ); + // Bridge tracing → log so our tracing::info! macros work + let _ = tracing_log::LogTracer::init(); }); }); }