Skip to content

Commit 837c57d

Browse files
committed
fix(model-client): watchdog in RestWebModelClient wasn't disposed
1 parent 36b1134 commit 837c57d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

model-client/src/jvmMain/kotlin/org/modelix/model/client/RestWebModelClient.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class RestWebModelClient @JvmOverloads constructor(
152152
}
153153
private var clientIdInternal: Int = 0
154154
private val coroutineScope = CoroutineScope(Dispatchers.Default)
155+
private var watchdogJob: Job? = null
155156
private val client = (providedClient ?: HttpClient(CIO)).config {
156157
this.followRedirects = false
157158
install(HttpTimeout) {
@@ -264,7 +265,7 @@ class RestWebModelClient @JvmOverloads constructor(
264265
private var connectionStatusListeners: Set<ConnectionStatusListener> = emptySet()
265266

266267
private fun startConnectionWatchdog() {
267-
coroutineScope.launch {
268+
watchdogJob = coroutineScope.launch {
268269
while (isActive) {
269270
try {
270271
connectNow()
@@ -274,7 +275,7 @@ class RestWebModelClient @JvmOverloads constructor(
274275
delay(3.seconds)
275276
}
276277
} catch (e: CancellationException) {
277-
break
278+
throw e
278279
} catch (e: Exception) {
279280
LOG.debug("", e)
280281
if (connectionStatus == ConnectionStatus.CONNECTED) {
@@ -361,6 +362,7 @@ class RestWebModelClient @JvmOverloads constructor(
361362
listeners.clear()
362363
}
363364
coroutineScope.cancel("model client disposed")
365+
watchdogJob?.cancel("model client disposed")
364366
}
365367

366368
override fun getPendingSize(): Int = pendingWrites.get()

0 commit comments

Comments
 (0)