-
-
Notifications
You must be signed in to change notification settings - Fork 278
fix potential segfault: dont use Companion in JNI calls and improve JNI ref releasing
#3354
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
Conversation
🚨 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:
|
Android Performance metrics 🚀
|
| 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 Report✅ All modified and coverable lines are covered by tests. 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. |
iOS Performance metrics 🚀
|
| 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 |
Companion in JNI callsCompanion in JNI calls and fix JNI ref releasing
Companion in JNI calls and fix JNI ref releasingCompanion in JNI calls and improve JNI ref releasing
📜 Description
Switch JNI/Dart calls from
native.SentryFlutterPlugin.Companion.xyz()tonative.SentryFlutterPlugin.xyz()No object lifetime hazards: Static calls use only a jclass and
CallStatic…Method. Companion calls use a Companion object andCall…Method, which can crash if the object ref is stale, not global, or used across threads.globalEnv_CallStaticObjectMethodvsglobalEnv_CallObjectMethodFixes #3353
Properly set up releasing of JNI Refs
Each
toJString()(and othertoJxyz()) 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 aroundglobalEnv_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
sendDefaultPiiis enabled🔮 Next steps