No error for EOF

This commit is contained in:
Philipp Heckel 2026-01-11 22:17:22 -05:00
parent 3a9daf40d7
commit 944f29a85d
3 changed files with 17 additions and 4 deletions

View file

@ -1,5 +1,8 @@
package io.heckel.ntfy.service
import okhttp3.internal.http2.StreamResetException
import java.io.EOFException
interface Connection {
fun start()
fun close()
@ -20,3 +23,10 @@ data class ConnectionId(
val clientCertHash: Int, // Hash of client certificate or 0 if none
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
}

View file

@ -16,6 +16,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import okhttp3.Call
import java.io.EOFException
import kotlin.random.Random
class JsonConnection(
@ -76,10 +77,11 @@ class JsonConnection(
Log.d(TAG, "[$url] Connection cancelled")
break
}
Log.e(TAG, "[$url] Connection failed: ${e.message}", e)
Log.d(TAG, "[$url] Connection broken, reconnecting ...")
retryMillis = nextRetryMillis(retryMillis, startTime)
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 ...")
delay(retryMillis)
}

View file

@ -1,7 +1,6 @@
package io.heckel.ntfy.service
import android.app.AlarmManager
import android.content.Context
import android.os.Build
import io.heckel.ntfy.db.ConnectionState
import io.heckel.ntfy.db.CustomHeader
@ -18,6 +17,7 @@ import okhttp3.OkHttpClient
import okhttp3.Response
import okhttp3.WebSocket
import okhttp3.WebSocketListener
import java.io.EOFException
import java.util.Calendar
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.atomic.AtomicReference
@ -186,7 +186,8 @@ class WsConnection(
errorCount++
val retrySeconds = RETRY_SECONDS.getOrNull(errorCount) ?: RETRY_SECONDS.last()
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)
}
}