Skip to content

Commit ebefec0

Browse files
committed
fix(model-client): memory leak in VersionChangeDetector
VersionChangeDetector wasn't disposed, while waiting for a change. It was transitively calling runBlocking from a coroutine which means a cancellation of the coroutine has no effect while being blocked.
1 parent b15ba97 commit ebefec0

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class RestWebModelClient @JvmOverloads constructor(
371371
return runBlocking { getA(key) }
372372
}
373373

374-
suspend fun getA(key: String): String? {
374+
override suspend fun getA(key: String): String? {
375375
val isHash = HashUtil.isSha256(key)
376376
if (isHash) {
377377
if (LOG.isDebugEnabled) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ abstract class VersionChangeDetector(
6969
store.listen(key, keyListener)
7070
while (isActive) {
7171
try {
72-
val version = store[key]
72+
val version = store.getA(key)
7373
if (version != lastVersionHash) {
7474
LOG.debug { "New version detected by polling: $version" }
7575
versionChanged(version)

model-datastructure/src/commonMain/kotlin/org/modelix/model/IKeyValueStore.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package org.modelix.model
1717

1818
interface IKeyValueStore {
1919
operator fun get(key: String): String?
20+
suspend fun getA(key: String): String? = get(key)
2021
fun put(key: String, value: String?)
2122
fun getAll(keys: Iterable<String>): Map<String, String?>
2223
fun putAll(entries: Map<String, String?>)

0 commit comments

Comments
 (0)