Commit f10f11d4 authored by Mygod's avatar Mygod

Handle race condition in disconnect vs callback

Our unregisterCallback is an oneway callback, meaning race conditions might happen. A quick fix is to check for callback.
parent 8555c629
......@@ -68,13 +68,16 @@ class ShadowsocksConnection(private val handler: Handler = Handler(),
private var callback: Callback? = null
private val serviceCallback = object : IShadowsocksServiceCallback.Stub() {
override fun stateChanged(state: Int, profileName: String?, msg: String?) {
handler.post { callback!!.stateChanged(state, profileName, msg) }
val callback = callback ?: return
handler.post { callback.stateChanged(state, profileName, msg) }
}
override fun trafficUpdated(profileId: Long, stats: TrafficStats) {
handler.post { callback!!.trafficUpdated(profileId, stats) }
val callback = callback ?: return
handler.post { callback.trafficUpdated(profileId, stats) }
}
override fun trafficPersisted(profileId: Long) {
handler.post { callback!!.trafficPersisted(profileId) }
val callback = callback ?: return
handler.post { callback.trafficPersisted(profileId) }
}
}
private var binder: IBinder? = null
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment