From 2514950d3839dcba6557f05292922287acadd589 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 4 Jun 2026 19:16:18 +0200 Subject: [PATCH] =?UTF-8?q?=E2=97=8F=20fix:=20handle=20undeliverable=20RxJ?= =?UTF-8?q?ava=20network=20exceptions=20globally?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a global RxJavaPlugins error handler in NextcloudTalkApplication to prevent crashes caused by ConnectException (ECONNREFUSED) arriving after a subscriber has already been disposed (e.g. user navigated away while a network call was in-flight). IOException and SocketException are logged and ignored since they represent expected network conditions. All other undeliverable exceptions are still forwarded to the uncaught exception handler so real bugs continue to surface as crashes. Signed-off-by: Marcel Hibbe --- .../talk/application/NextcloudTalkApplication.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt index f9af670d5e..fefa53d474 100644 --- a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt @@ -60,9 +60,13 @@ import com.vanniktech.emoji.EmojiManager import com.vanniktech.emoji.google.GoogleEmojiProvider import de.cotech.hw.SecurityKeyManager import de.cotech.hw.SecurityKeyManagerConfig +import io.reactivex.exceptions.UndeliverableException +import io.reactivex.plugins.RxJavaPlugins import okhttp3.OkHttpClient import org.conscrypt.Conscrypt import org.webrtc.PeerConnectionFactory +import java.io.IOException +import java.net.SocketException import java.security.Security import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -122,6 +126,16 @@ class NextcloudTalkApplication : Log.d(TAG, "onCreate") sharedApplication = this + RxJavaPlugins.setErrorHandler { e -> + var throwable: Throwable = if (e is UndeliverableException) e.cause ?: e else e + if (throwable is IOException || throwable is SocketException) { + Log.w(TAG, "Undeliverable network exception ignored", throwable) + return@setErrorHandler + } + Thread.currentThread().uncaughtExceptionHandler + ?.uncaughtException(Thread.currentThread(), throwable) + } + val securityKeyManager = SecurityKeyManager.getInstance() val securityKeyConfigBuilder = SecurityKeyManagerConfig.Builder() .setEnableDebugLogging(BuildConfig.DEBUG)