From 795caee54dc79502e82590ea114d2b55cf73c160 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 8 Nov 2020 01:48:43 -0500 Subject: [PATCH] Prevent RootServer.create cancelling the entire scope --- mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt | 2 +- .../src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt index 9b8e5a68..2072db7a 100644 --- a/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt +++ b/mobile/src/main/java/be/mygod/librootkotlinx/RootServer.kt @@ -270,7 +270,7 @@ class RootServer { @Throws(RemoteException::class) fun create(command: RootCommandChannel, scope: CoroutineScope, classLoader: ClassLoader?) = scope.produce( - capacity = command.capacity.also { + SupervisorJob(), command.capacity.also { when (it) { Channel.UNLIMITED, Channel.CONFLATED -> { } else -> throw IllegalArgumentException("Unsupported channel capacity $it") diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt index a3494577..3fc6f26a 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt @@ -21,7 +21,6 @@ import timber.log.Timber import java.io.IOException import java.io.InterruptedIOException import kotlin.concurrent.thread -import kotlin.coroutines.EmptyCoroutineContext abstract class IpMonitor { companion object { @@ -109,7 +108,7 @@ abstract class IpMonitor { if (destroyed) return@thread } try { - runBlocking(EmptyCoroutineContext + worker) { + runBlocking(worker) { RootManager.use { server -> // while we only need to use this server once, we need to also keep the server alive handleChannel(server.create(ProcessListener(errorMatcher, Routing.IP, "monitor", monitoredObject),