No error for EOF
This commit is contained in:
parent
3a9daf40d7
commit
944f29a85d
3 changed files with 17 additions and 4 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
package io.heckel.ntfy.service
|
package io.heckel.ntfy.service
|
||||||
|
|
||||||
|
import okhttp3.internal.http2.StreamResetException
|
||||||
|
import java.io.EOFException
|
||||||
|
|
||||||
interface Connection {
|
interface Connection {
|
||||||
fun start()
|
fun start()
|
||||||
fun close()
|
fun close()
|
||||||
|
|
@ -20,3 +23,10 @@ data class ConnectionId(
|
||||||
val clientCertHash: Int, // Hash of client certificate or 0 if none
|
val clientCertHash: Int, // Hash of client certificate or 0 if none
|
||||||
val reconnectVersion: Long // Incremented to force reconnection for this baseUrl
|
val reconnectVersion: Long // Incremented to force reconnection for this baseUrl
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun isConnectionBrokenException(t: Throwable): Boolean {
|
||||||
|
return t is EOFException
|
||||||
|
|| t.cause is EOFException
|
||||||
|
|| t is StreamResetException
|
||||||
|
|| t.cause is StreamResetException
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.Call
|
import okhttp3.Call
|
||||||
|
import java.io.EOFException
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
class JsonConnection(
|
class JsonConnection(
|
||||||
|
|
@ -76,10 +77,11 @@ class JsonConnection(
|
||||||
Log.d(TAG, "[$url] Connection cancelled")
|
Log.d(TAG, "[$url] Connection cancelled")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
Log.e(TAG, "[$url] Connection failed: ${e.message}", e)
|
Log.d(TAG, "[$url] Connection broken, reconnecting ...")
|
||||||
retryMillis = nextRetryMillis(retryMillis, startTime)
|
retryMillis = nextRetryMillis(retryMillis, startTime)
|
||||||
val nextRetryTime = System.currentTimeMillis() + retryMillis
|
val nextRetryTime = System.currentTimeMillis() + retryMillis
|
||||||
connectionDetailsListener(subscriptionIds, ConnectionState.CONNECTING, e, nextRetryTime)
|
val error = if (isConnectionBrokenException(e)) null else e
|
||||||
|
connectionDetailsListener(subscriptionIds, ConnectionState.CONNECTING, error, nextRetryTime)
|
||||||
Log.w(TAG, "[$url] Retrying connection in ${retryMillis / 1000}s ...")
|
Log.w(TAG, "[$url] Retrying connection in ${retryMillis / 1000}s ...")
|
||||||
delay(retryMillis)
|
delay(retryMillis)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package io.heckel.ntfy.service
|
package io.heckel.ntfy.service
|
||||||
|
|
||||||
import android.app.AlarmManager
|
import android.app.AlarmManager
|
||||||
import android.content.Context
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import io.heckel.ntfy.db.ConnectionState
|
import io.heckel.ntfy.db.ConnectionState
|
||||||
import io.heckel.ntfy.db.CustomHeader
|
import io.heckel.ntfy.db.CustomHeader
|
||||||
|
|
@ -18,6 +17,7 @@ import okhttp3.OkHttpClient
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.WebSocket
|
import okhttp3.WebSocket
|
||||||
import okhttp3.WebSocketListener
|
import okhttp3.WebSocketListener
|
||||||
|
import java.io.EOFException
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
@ -186,7 +186,8 @@ class WsConnection(
|
||||||
errorCount++
|
errorCount++
|
||||||
val retrySeconds = RETRY_SECONDS.getOrNull(errorCount) ?: RETRY_SECONDS.last()
|
val retrySeconds = RETRY_SECONDS.getOrNull(errorCount) ?: RETRY_SECONDS.last()
|
||||||
val nextRetryTime = System.currentTimeMillis() + (retrySeconds * 1000L)
|
val nextRetryTime = System.currentTimeMillis() + (retrySeconds * 1000L)
|
||||||
connectionDetailsListener(subscriptionIds, ConnectionState.CONNECTING, t, nextRetryTime)
|
val error = if (isConnectionBrokenException(t)) null else t
|
||||||
|
connectionDetailsListener(subscriptionIds, ConnectionState.CONNECTING, error, nextRetryTime)
|
||||||
scheduleReconnect(retrySeconds)
|
scheduleReconnect(retrySeconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue