Status Update
Comments
uc...@google.com <uc...@google.com> #2
* GC ROOT android.support.v4.media.session.MediaSessionCompat$MediaSessionImplApi21$ExtraSession.this$0
* references android.support.v4.media.session.MediaSessionCompat$MediaSessionImplApi21.mSessionObj
* references android.media.session.MediaSession.mController
* references android.media.session.MediaController.mContext
* leaks com.bubenheimer.rucksack.d.q instance
il...@gmail.com <il...@gmail.com> #3
il...@gmail.com <il...@gmail.com> #4
vs...@google.com <vs...@google.com>
en...@google.com <en...@google.com> #5
Can you please confirm whether this is still reproducible on API 33?
And if you happen to have access, also on the Developer Preview of API 34?
zy...@google.com <zy...@google.com> #6
en...@google.com <en...@google.com> #7
Final thing, is this a dup of
en...@google.com <en...@google.com> #8
Thanks, I believe it's a dup at this point.
The other issue was marked as fixed a year ago, but is still as reproducible as ever, I had just tested it on API 33 and UpsideDownCake DP2.
jo...@googlemail.com <jo...@googlemail.com> #9
I suppose I cannot say for sure that the two issues have the same root cause, there may be more than one cause for MediaBrowserService(Compat) leaks.
I just tested this issue here once more on my production app, on API 33 (emulator), and got a leak trace (with current LeakCanary) that closely resembles the original one I posted years ago. I let the app sit idle for another half hour, occasionally forcing a garbage collection via Android Studio Profiler, but my destroyed MediaBrowserServiceCompat (CW) instance just would not release. (I validated non-release by logging from finalize()
method, which looks very reliable.)
====================================
HEAP ANALYSIS RESULT
====================================
1 APPLICATION LEAKS
References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.
Signature: 881c4404fc048402f456764f134ed07390863849
┬───
│ GC Root: Global variable in native code
│
├─ android.os.Handler$MessengerImpl instance
│ Leaking: UNKNOWN
│ ↓ Handler$MessengerImpl.this$0
│ ~~~~~~
├─ androidx.media.MediaBrowserServiceCompat$ServiceHandler instance
│ Leaking: UNKNOWN
│ this$0 instance of com.bubenheimer.rucksack.d.CW
│ ↓ MediaBrowserServiceCompat$ServiceHandler.this$0
│ ~~~~~~
╰→ com.bubenheimer.rucksack.d.CW instance
Leaking: YES (ObjectWatcher was watching this because com.bubenheimer.rucksack.d.CW received Service#onDestroy()
callback and Service not held by ActivityThread)
key = 0cda35fa-fa79-4035-89ca-6ab496bd1ddc
watchDurationMillis = 5400
retainedDurationMillis = 392
mApplication instance of com.bubenheimer.rucksack.d.D
mBase instance of android.app.ContextImpl
====================================
0 LIBRARY LEAKS
A Library Leak is a leak caused by a known bug in 3rd party code that you do not have control over.
See https://square.github.io/leakcanary/fundamentals-how-leakcanary-works/#4-categorizing-leaks
====================================
0 UNREACHABLE OBJECTS
An unreachable object is still in memory but LeakCanary could not find a strong reference path
from GC roots.
====================================
METADATA
Please include this in bug reports and Stack Overflow questions.
Build.VERSION.SDK_INT: 33
Build.MANUFACTURER: Google
LeakCanary version: 2.10
App process name: com.bubenheimer.rucksack
Class count: 28324
Instance count: 179717
Primitive array count: 132390
Object array count: 25025
Thread count: 39
Heap total bytes: 27055417
Bitmap count: 0
Bitmap total bytes: 0
Large bitmap count: 0
Large bitmap total bytes: 0
Db 1: open /data/user/0/com.bubenheimer.rucksack/databases/com.google.android.datatransport.events
Db 2: open /data/user/0/com.bubenheimer.rucksack/databases/rucksack-5031356898991293088.db
Stats: LruCache[maxSize=3000,hits=32348,misses=41728,hitRate=43%]
RandomAccess[bytes=1991236,reads=41728,travel=35597905162,range=32212305,size=40115227]
Heap dump reason: 1 retained objects, app is visible
Analysis duration: 16991 ms
Heap dump file path: /storage/emulated/0/Download/leakcanary-com.bubenheimer.rucksack/2023-04-25_11-53-35_598.hprof
Heap dump timestamp: 1682438042701
Heap dump duration: 4546 ms
====================================
ch...@gmx.de <ch...@gmx.de> #10
I ended up letting the app sit idle for an hour, but the service still would not finalize.
ts...@gmail.com <ts...@gmail.com> #11
I also tried this, but still no finalization:
adb shell am send-trim-memory com.bubenheimer.rucksack:appexternal RUNNING_CRITICAL
yo...@gmail.com <yo...@gmail.com> #12
I've dug into this further, and identified a leak in AndroidX code that I was using (
Eliminating this leak lets the MediaBrowserService(Compat) call its finalizer eventually. I assume that the leak-related fixes in API 33 are also essential for reaching this stage.
However, there is still some unidentified holdup between onDestroy() and finalize() in my production app triggering various LeakCanary traces, before finalization after about 30 seconds. (LeakCanary triggers garbage collections, but those do not force finalization in this case.)
I assume the holdup is related to more general problems with service/binder/messenger cleanup. It's an issue, because it makes it very difficult to spot more real problems.
Can anything be done to eliminate these delays?
I am attaching the various leak traces I got from excluding each, one at a time (this is how I eventually found the AndroidX leak).
ch...@gmail.com <ch...@gmail.com> #13
I think the issue can be closed, I am no longer able to reproduce the delayed finalization issue, and I am hoping to switch to media3 MediaSessionService anyway. I have not tried the minimal repro again, though. Ultimately I think the API 33 fixes took care of what was broken here, in addition to avoiding the referenced AndroidX leak.
Thank you for your effort to reopen this.
bo...@gmail.com <bo...@gmail.com> #14
PY Ricau, the guy behind LeakCanary, suggested that there is more to this, and that there are several actual leaks here. I will update this issue with more info as soon as I find some time, I'm in a bit of a crunch right now.
me...@morl.au <me...@morl.au> #15
The 3 LeakCanary leak reports that I attached above point at 2 distinct leaks that are still real, according to PY's analysis from the Github issue here:
Can these leaks be addressed, please?
MediaBrowserServiceCompat$ServiceHandler is an inner class of MediaBrowserServiceCompat (super class of CW) and it's there so that your service can respond to IPC callbacks. It extends Handler and is passed to a Messenger instance created by MediaBrowserServiceCompat in onCreate(), and that Messenger essentially pulls a Binder out of the Handler and passes that binder back to anything calling your service. In other words, every time something binds to your service, the thing that binds to your service is getting an indirect reference to the ServiceHandler which allows it to post messages to that handler which the service will eventually process. However, for this to work, the native framework code keeps a strong native reference locally to the binder until the calling service finalizes the ownership of the binder on its side.
This is actually a common leak pattern in the Android framework: binders are held until the other side runs garbage collection and finalizes the binder on its end, no matter what we're doing with service lifecycle (that's because binders are used beyond services, the only way to be certain the other side won't call is when it doesn't have that pointer). The proper way to handler this is for the service code to finish its handler in onDestroy, or set the reference from the handler to the service to null in onDestroy.
The first and second leak traces are identical, the problem is that MediaBrowserServiceCompat$ServiceHandler has several direct and indirect references to the service.
The last leak is the exact same issue elsewhere, ExtraSession is a stub that won't be GCed until the other side has run its own GC
https://github.com/aosp-mirror/platform_frameworks_support/blob/a9ac247af2afd4115c3eb6d16c05bc92737d6305/media/src/main/java/android/support/v4/media/session/MediaSessionCompat.java#L3413
So these 2 leaks are binder related leaks, and the leaks stay in place until a GC runs in the calling process, and you have no control over that. They really should be fixed.
me...@morl.au <me...@morl.au> #16
I've not been able to reproduce the leak on a device running Android 14 (UDC / API 34).
For unimportant reasons I had to build my own toy app from scratch (using
me...@morl.au <me...@morl.au> #17
In conclusion, I was able to reproduce on S (Android 12), but unable to reproduce the issue on T (Android 13) or U (Android 14). I'm attaching the project I used for testing in case you find anything wrong.
Can you use that project to reproduce the issue? If yes, we need to figure out what we are doing differently. Also please kindly include a bugreport (running adb bugreport
shortly after the leak is detected) if you are able to repro.
Please assign back to me once you've replied (if you are not able to, ignore).
ba...@gmail.com <ba...@gmail.com> #18
I've beefed up your example to make it repro the leaks that I attached in #12. I'll attach the updated example. The relevant changes were:
- Run service & receiver in separate process from Activity.
- Customize LeakCanary to support multiple processes.
- Add some additional media-related code to trigger a leak.
Even when not running the service in a separate process there is a leak in the Activity. I'll attach that one, too. May be a similar root cause. I have not investigated this one.
I am attaching the bugreport, too. I took it right after LeakCanary GC'ed and detected a leak. (About 5 seconds after onDestroy().) But it looks easy to reproduce now.
ch...@gmx.de <ch...@gmx.de> #19
(I did the repro on API 33)
ar...@gmail.com <ar...@gmail.com> #20
Also, I don't think non-Googlers are able to reassign an issue, so please take it from here.
ar...@gmail.com <ar...@gmail.com> #21
Thanks. Will provide an update in the next few days.
fe...@gmail.com <fe...@gmail.com> #22
Correct me if I'm wrong but the only issue we are aware that still exists is in MediaBrowserServiceCompat, right? (not in the platform MediaBrowserService)
I've sent
Once merged, you should just need to update your androidx.media dependency to pick up the fix.
ni...@gmail.com <ni...@gmail.com> #23
Thanks for the fix.
I'd think that MediaSessionCompat needs a similar fix, based on the leak traces (MediaBrowserServiceCompatLeak4.txt & MediaBrowserActivityLeak.txt) and PY's comments. You can repro MediaBrowserActivityLeak.txt by running the service in the same process as the Activity.
I'll ping PY about possibly chiming in on the code review.
t....@gmail.com <t....@gmail.com> #24
The change has now been merged. I'll now look into the media session compat issue, which seems to persist.
ch...@gmail.com <ch...@gmail.com> #25
Sorry for the late review. Not sure if you get notifications there, I left a comment:
TL;DR is that using weak refs isn't ideal, you could stick to a strong ref set to null from Service.onDestroy()
sa...@gmail.com <sa...@gmail.com> #26
Ack. Will implement the proposed fix.
ma...@gmail.com <ma...@gmail.com> #27
Есть ли утечка информации?
ad...@gmail.com <ad...@gmail.com> #28
Есть ли утечка информации?
According to translate: Is there any information leak?
No. This is a resources leak, no security issues here.
vi...@gmail.com <vi...@gmail.com> #29
Another fix for MediaSessionCompat...ExtraSession here:
Only one pending fix after this change is MediaSessionCompat...MediaSessionStub, after which I plan to mark this as fixed. Still, people should migrate to media3, but at least you can upgrade your MediaSessionCompat dep to get a quick fix of the leaks. Feel free to leave any comments here or in the patch.
ak...@gmail.com <ak...@gmail.com> #30
If there are more leaks to fix in androidx, please kindly file a fresh issue.
ak...@gmail.com <ak...@gmail.com> #31
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.media:media:1.7.0-beta01
ma...@gmail.com <ma...@gmail.com> #33
Also note that the example uses media 1.7.0 so fixes above should be included already.
a6...@gmail.com <a6...@gmail.com> #34
@ke...@gmail.com might be an issue with MediaSessionCompat, but we'll need a fresh ticket to look into this.
a6...@gmail.com <a6...@gmail.com> #35
Should I create that one then?
en...@google.com <en...@google.com> #36
en...@google.com <en...@google.com> #37
bl...@gmail.com <bl...@gmail.com> #38
en...@google.com <en...@google.com> #39
sc...@gmail.com <sc...@gmail.com> #40
en...@google.com <en...@google.com> #41
bl...@gmail.com <bl...@gmail.com> #42
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
downloaded last night from:
en...@google.com <en...@google.com> #43
bl...@gmail.com <bl...@gmail.com> #44
en...@google.com <en...@google.com> #45
but it doesn't really make sense: you really shouldn't be on that codepath talking to a 6P. i think JellyBean was the last release that used the older sideload method! it looks like we'll give the old method a go regardless of how the new method fails. so my suspicion is that your real problem is that adb isn't able to talk to your 6P and falls back to the old method just in case (even though we know that won't work because the 6P is too new, adb doesn't).
the output from
adb kill-server
set ADB_TRACE=all
adb sideload <whatever you've been doing>
might be informative.
bl...@gmail.com <bl...@gmail.com> #46
en...@google.com <en...@google.com> #47
(have you ever sideloaded before? you know that you have to get the device ready to receive before "adb sideload" will work?)
am...@gmail.com <am...@gmail.com> #48
bl...@gmail.com <bl...@gmail.com> #49
List of devices attached
8XV7N15B24004979 device
Is that my device?
I have never sideloaded. I haven't messed with a rom since Samsung S3 days.
I would think that it sees my device since I can do the "adb reboot recovery"
en...@google.com <en...@google.com> #50
@miguel: that's actually a 6P bug where it drops off USB when it reboots. i'm assuming that's fixed in O, but you're right that it might be worth adding an "adb devices" step to the instructions. i'll see what i can do.
i've uploaded
$ adb sideload mysid-ota-424425.zip
adb: sideload connection failed: no devices/emulators found
adb: trying pre-KitKat sideload method...
adb: pre-KitKat sideload connection failed: no devices/emulators found
bl...@gmail.com <bl...@gmail.com> #51
i unplugged and replugged in my phone and got a installing drivers screen. looks like it is working now???!!
I'm at the serving :~2% so far.
lo...@gmail.com <lo...@gmail.com> #52
bl...@gmail.com <bl...@gmail.com> #53
cb...@gmail.com <cb...@gmail.com> #54
cb...@gmail.com <cb...@gmail.com> #55
en...@google.com <en...@google.com> #56
ja...@gmail.com <ja...@gmail.com> #57
opening '.\marlin-ota-n2g47o-61bf55a3.zip'...
connecting...
falling back to older sideload method...
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
I tried unplugging and plugging back in once recovery was up, no change.
ja...@gmail.com <ja...@gmail.com> #58
en...@google.com <en...@google.com> #59
i've also updated the public instructions at
li...@gmail.com <li...@gmail.com> #60
PS C:\Users\wohen> adb reboot sideload "D:\download\Compressed\update.zip"
PS C:\Users\wohen> adb sideload "D:\download\Compressed\update.zip"
loading: 'D:\download\Compressed\update.zip'...
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
...........................................................
en...@google.com <en...@google.com> #61
am...@gmail.com <am...@gmail.com> #62
am...@gmail.com <am...@gmail.com> #63
da...@gmail.com <da...@gmail.com> #64
sa...@gmail.com <sa...@gmail.com> #65
sa...@gmail.com <sa...@gmail.com> #66
al...@gmail.com <al...@gmail.com> #67
az...@gmail.com <az...@gmail.com> #68
[Deleted User] <[Deleted User]> #69
10...@gmail.com <10...@gmail.com> #70
[Deleted User] <[Deleted User]> #71
ka...@gmail.com <ka...@gmail.com> #72
[Deleted User] <[Deleted User]> #73
gi...@gmail.com <gi...@gmail.com> #76
gi...@gmail.com <gi...@gmail.com> #77
..and JR of you still want to be with some that evil to hurt little 14 and 12 year old girls go for it. And be sure and bring your gun like you promised in your encrypted letter I decoded.....I wasnt scared when I drove to Texas for kayla and my front door is open every night . So if that's who you are so be it I'm scared of no man! I just hope your not that stupid in both manners frankly but do as ye will. And I'll be waiting.
ab...@gmail.com <ab...@gmail.com> #78
انتهاك خصوصية
Description
Platform-tools rev.25.0.4
Steps to reproduce:
1. Run "adb sideload <file>".
2. Error is here.
On Platform-tools rev.25.0.3 its fine.