novoda / merlin

Observes network connection status & gives callbacks
Other
543 stars 79 forks source link

IllegalStateException - You must call canNotify() before calling notify(ConnectivityChangeEvent) #171

Closed ouchadam closed 6 years ago

ouchadam commented 6 years ago

Problem

Have seen a single crash in crashlytics with


IllegalStateException - You must call canNotify() before calling notify(ConnectivityChangeEvent)

com.novoda.merlin.service.MerlinService$LocalBinder.notify (SourceFile:81)
com.novoda.merlin.receiver.ConnectivityCallbacks.notifyMerlinService (SourceFile:45)
com.novoda.merlin.receiver.ConnectivityCallbacks.onAvailable (SourceFile:26)
android.net.ConnectivityManager$CallbackHandler.handleMessage (ConnectivityManager.java:2807)
android.os.Handler.dispatchMessage (Handler.java:105)
android.os.Looper.loop (Looper.java:164)
android.os.HandlerThread.run (HandlerThread.java:65)

This should be impossible since the call to notify is guarded with a canNotify however, it appears this was running on a background HandlerThread meaning it's possible the service became unbound during act of notifying

Potential Solution

To force interactions with the service to be via the main thread to ensure the guard and notification are always serial

Impact