Possible memory leak
Hello,
In December 8, 2018 we had problems with APNS push delivery. not sure what was a root cause, but looks like there were problems at Apple side. Problem is that we finally got FullGC and at the top were pushy objects although we have limit on 10k pushes in delivering:
Dec 8 03:30:17 num #instances #bytes class name
Dec 8 03:30:17 ----------------------------------------------
Dec 8 03:30:17 1: 8590451 2369924768 [C
Dec 8 03:30:17 2: 2567468 310368816 [I
Dec 8 03:30:17 3: 7969847 191276328 java.lang.String
Dec 8 03:30:17 4: 4968091 158978912 io.netty.util.concurrent.DefaultPromise
Dec 8 03:30:17 5: 144608 119128456 [J
Dec 8 03:30:17 6: 2484032 99361280 com.turo.pushy.apns.util.SimpleApnsPushNotification
Dec 8 03:30:17 7: 12 93706024 [F
Dec 8 03:30:17 8: 297861 87061232 [B
Dec 8 03:30:17 9: 2484032 79489024 com.turo.pushy.apns.ApnsClient$2
we use pushy 0.11.0. Looks like these objects are from ApnsClientHandler maps unattachedPushNotificationsByStreamId and unattachedResponsePromisesByStreamId. In ApnsClientHandler::writePushNotification notification and promise are put in map, but on onStreamAdded are removed. Have checked latest version, there is only unattachedResponsePromisesByStreamId map, but the rest seems the same. By briefly looking netty code, seems that there is no guarantee that onStreamAdded is always called, so looks like there is possibility that unattachedResponsePromisesByStreamId could grow without limit. Could it be true?
Thanks, Z.
By briefly looking netty code, seems that there is no guarantee that
onStreamAddedis always called, so looks like there is possibility thatunattachedResponsePromisesByStreamIdcould grow without limit.
Can you say more about this? Intuitively, it feels like you might be on to something (and this could be an important clue for #659/#142), but in your assessment, what conditions would lead to onStreamAdded not getting called?
It just guess that onStreamAdded is not called. because as I can see only here objects are removed from maps. it is just guess again that promises and notifications are not cleaned by gc, because they are held in these maps (and probably elsewhere, but maps seems the best candidates). I only have class histograms when Full GC started to happen and finally application stuck in it, and there are lot of HashMap$Node instances: 13: 1034896 33116672 java.util.HashMap$Node
Count of promises, notifications grows from Full GC to Full GC, although I see from logs, that count of currently sending pushes are below our limits (10k). Will try some simulations tomorrow.
there are lot of HashMap$Node instances: 13: 1034896 33116672 java.util.HashMap$Node
Interesting; the map of unattached promises is a io.netty.util.collection.IntObjectHashMap, which does not extend java.util.HashMap. I think we should still clear that map, but I'm wondering where else we might be piling up HashMap nodes. I'll look around and see what I can figure out.
Ouch, did not pay attention to it:(. Tomorrow will check more histogram for pushy related objects. Yesterday have tried latest pushy version in development environment. Have played with blocking in/out connections to Apple with firewall. Seems that everything worked great.
Hi, Jon. I'm closing this issue. We do lot of in-memory caching and I think these HashMap nodes don't relate to pushy. I'm still don't understand why there are so many DefaultPromise and SimpleApnsPushNotification instances, but without full heap dump seems that it is not possible to tell what gc roots are. Have asked devops to make full heap damp before restart, if such problem will repeat. Maybe there are problems on our side. I'll let you know if we find something.
Thanks, Z.
Let's actually keep this open. I think the thing you found actually points to another bug where, if a connection closes with some unattached promises, those promises may never get resolved. That may, indeed, be leading to a kind of leak even if it's not exactly the one you're looking for.