1

We are currently developing an kotlin app that uses Pusher Beams. It runs really well, till hit with a certain amount of notifications per second (4+). Then commonly fails with one of those two exceptions:

Fatal Exception: java.lang.OutOfMemoryError: Could not allocate JNI Env
   at java.lang.Thread.nativeCreate(Thread.java)
   at java.lang.Thread.start(Thread.java:730)
   at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:941)
   at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1359)
   at okhttp3.ConnectionPool.put(ConnectionPool.java:153)

Or

Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. 
   at android.database.CursorWindow.<init>(CursorWindow.java:108)
   at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
   at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:138)
   at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)

Since both exceptions seem to decline to allocate more memory we analyzed the app with the Profiler. There the consumption looks stable, till it crashes. As well added LeakCanary which does not report any (known) leaks... Only instances of the MessagingService and connections of okhttp seem to live / be open for a longer time than necessary.

Here a snippet of my Service:

class NotificationService : MessagingService() {

    ...

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        val data = remoteMessage.data

        if(data.containsKey("action")){
            val action = data["action"].toString()

            if(action == "ticketUpdate"){
                val json = Json(JsonConfiguration.Stable)
                val tickets: List<Ticket> = json.parse(Ticket.serializer().list, data["tickets"].toString())

                val ticketIterator = tickets.iterator()
                ticketIterator.forEach { ticket ->
                    ticketHelper.updateTicket(ticket)
                }
            }
        }
    }
}
  • Do we handle incoming messages wrongly?
  • How to continue debugging this issue?
  • I did not find any limitations regarding that on the throughput of fcm messages. Are there any known issues with this on the pusher part?
binzram
  • 530
  • 4
  • 13

1 Answers1

0

Well took a while, but solved my issue:

https://github.com/pusher/push-notifications-android/pull/106

binzram
  • 530
  • 4
  • 13