Skip to content

Conversation

@buenaflor
Copy link
Contributor

@buenaflor buenaflor commented Nov 19, 2025

📜 Description

Switch JNI/Dart calls from native.SentryFlutterPlugin.Companion.xyz() to native.SentryFlutterPlugin.xyz()

No object lifetime hazards: Static calls use only a jclass and CallStatic…Method. Companion calls use a Companion object and Call…Method, which can crash if the object ref is stale, not global, or used across threads.globalEnv_CallStaticObjectMethod vs globalEnv_CallObjectMethod

Fixes #3353

Properly set up releasing of JNI Refs

Each toJString() (and other toJxyz()) creates a JNI local reference. releasedBy(arena) defers deletion until the arena ends, so building big maps/lists holds hundreds/thousands of locals at once. That can overflow the per-thread local reference table and crash around globalEnv_NewString/AddGlobalRef.

Fixes #3348

💡 Motivation and Context

Potentially fixes #3348 and #3353

💚 How did you test it?

Unfortunately I could not repro the crashes referenced in the issue.

But the existing integration tests should still work with this change

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

🔮 Next steps

@github-actions
Copy link
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:

  • packages/flutter/lib/src/native/java/android_replay_recorder.dart

@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2025

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 487.24 ms 473.66 ms -13.58 ms
Size 13.93 MiB 15.18 MiB 1.25 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
ad121c0 353.85 ms 358.80 ms 4.95 ms
2cf9161 454.12 ms 512.67 ms 58.55 ms
c1e775e 482.36 ms 608.98 ms 126.62 ms
7b21e8b 467.74 ms 466.24 ms -1.50 ms
9b99523 456.91 ms 490.55 ms 33.64 ms
cc4e375 426.15 ms 482.34 ms 56.19 ms
6bcdc99 440.23 ms 435.77 ms -4.46 ms
a69a51f 437.18 ms 450.60 ms 13.42 ms
6b69699 456.06 ms 557.44 ms 101.38 ms
819c1e7 449.80 ms 442.98 ms -6.82 ms

App size

Revision Plain With Sentry Diff
ad121c0 13.93 MiB 15.06 MiB 1.13 MiB
2cf9161 6.54 MiB 7.70 MiB 1.16 MiB
c1e775e 6.54 MiB 7.70 MiB 1.17 MiB
7b21e8b 13.93 MiB 15.00 MiB 1.06 MiB
9b99523 6.54 MiB 7.69 MiB 1.15 MiB
cc4e375 6.54 MiB 7.69 MiB 1.15 MiB
6bcdc99 13.93 MiB 15.00 MiB 1.06 MiB
a69a51f 13.93 MiB 15.06 MiB 1.13 MiB
6b69699 6.54 MiB 7.70 MiB 1.17 MiB
819c1e7 13.93 MiB 15.00 MiB 1.06 MiB

Previous results on branch: fix/segfault

Startup times

Revision Plain With Sentry Diff
f2c85c0 449.14 ms 461.86 ms 12.72 ms
69cd270 373.60 ms 374.26 ms 0.66 ms
a584335 360.74 ms 365.60 ms 4.86 ms

App size

Revision Plain With Sentry Diff
f2c85c0 13.93 MiB 15.18 MiB 1.25 MiB
69cd270 13.93 MiB 15.18 MiB 1.25 MiB
a584335 13.93 MiB 15.18 MiB 1.25 MiB

@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.96%. Comparing base (ef47ff6) to head (52f7999).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3354      +/-   ##
==========================================
+ Coverage   88.47%   89.96%   +1.48%     
==========================================
  Files         291       95     -196     
  Lines        9917     3198    -6719     
==========================================
- Hits         8774     2877    -5897     
+ Misses       1143      321     -822     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2025

iOS Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1273.96 ms 1268.62 ms -5.34 ms
Size 5.53 MiB 6.02 MiB 501.22 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
6ad8fc4 1263.70 ms 1266.06 ms 2.36 ms
c8596a6 1234.11 ms 1241.19 ms 7.08 ms
c0dde50 1268.90 ms 1275.61 ms 6.71 ms
2cf9161 1248.33 ms 1266.55 ms 18.22 ms
c1e775e 1263.08 ms 1275.32 ms 12.24 ms
bfabaf2 1251.72 ms 1253.38 ms 1.67 ms
7b21e8b 1256.79 ms 1267.12 ms 10.33 ms
d0aa4b6 1268.23 ms 1268.39 ms 0.15 ms
54acf91 1257.65 ms 1277.96 ms 20.31 ms
192b44c 1269.08 ms 1275.52 ms 6.44 ms

App size

Revision Plain With Sentry Diff
6ad8fc4 5.53 MiB 6.01 MiB 487.65 KiB
c8596a6 7.86 MiB 9.44 MiB 1.58 MiB
c0dde50 5.53 MiB 6.01 MiB 488.14 KiB
2cf9161 7.86 MiB 9.44 MiB 1.58 MiB
c1e775e 20.70 MiB 22.46 MiB 1.75 MiB
bfabaf2 5.53 MiB 6.01 MiB 487.95 KiB
7b21e8b 5.53 MiB 6.00 MiB 479.96 KiB
d0aa4b6 5.53 MiB 6.02 MiB 502.04 KiB
54acf91 20.70 MiB 22.46 MiB 1.75 MiB
192b44c 5.53 MiB 5.96 MiB 444.33 KiB

Previous results on branch: fix/segfault

Startup times

Revision Plain With Sentry Diff
69cd270 1258.27 ms 1264.23 ms 5.96 ms
a584335 1273.76 ms 1281.71 ms 7.96 ms

App size

Revision Plain With Sentry Diff
69cd270 5.53 MiB 6.02 MiB 501.22 KiB
a584335 5.53 MiB 6.02 MiB 501.24 KiB

@buenaflor buenaflor changed the title fix potential segfault: dont use Companion in JNI calls fix potential segfault: dont use Companion in JNI calls and fix JNI ref releasing Nov 19, 2025
@buenaflor buenaflor changed the title fix potential segfault: dont use Companion in JNI calls and fix JNI ref releasing fix potential segfault: dont use Companion in JNI calls and improve JNI ref releasing Nov 19, 2025
@buenaflor buenaflor merged commit cdf371b into main Nov 20, 2025
69 of 70 checks passed
@buenaflor buenaflor deleted the fix/segfault branch November 20, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants