Skip to content

Commit 6a40fd6

Browse files
committed
Add timeout to loading mappings
1 parent 0c9c93b commit 6a40fd6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/kotlin/me/shedaniel/linkie/MappingsSupplier.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ package me.shedaniel.linkie
55
import com.soywiz.korio.file.VfsFile
66
import kotlinx.coroutines.sync.Mutex
77
import kotlinx.coroutines.sync.withLock
8+
import kotlinx.coroutines.withTimeout
9+
import kotlinx.coroutines.withTimeoutOrNull
810
import me.shedaniel.linkie.utils.div
911
import me.shedaniel.linkie.utils.error
1012
import me.shedaniel.linkie.utils.info
13+
import kotlin.time.Duration.Companion.seconds
1114

1215
interface MappingsSupplier {
1316
fun isApplicable(version: String): Boolean
@@ -78,10 +81,12 @@ private class NamespacedMappingsSupplier(val namespace: Namespace, mappingsSuppl
7881
override suspend fun applyVersion(version: String): MappingsContainer {
7982
mutex.withLock {
8083
Namespaces.limitCachedData(1)
81-
return getCachedVersion(version) ?: super.applyVersion(version).also {
84+
return getCachedVersion(version) ?: withTimeoutOrNull(20.seconds) {
85+
super.applyVersion(version)
86+
}?.also {
8287
it.namespace = namespace.id
8388
Namespaces.addMappingsContainer(it)
84-
}
89+
} ?: throw IllegalStateException("TIMED OUT! Failed to load $version in $namespace.")
8590
}
8691
}
8792

0 commit comments

Comments
 (0)