Skip to content

Commit b868f5e

Browse files
committed
fix: useStorage race
Signed-off-by: Bartosz Czyż <czyzbartosz3@gmail.com>
1 parent 73c95b8 commit b868f5e

File tree

1 file changed

+4
-13
lines changed
  • here-naksha-lib-model/src/commonMain/kotlin/naksha/model

1 file changed

+4
-13
lines changed

here-naksha-lib-model/src/commonMain/kotlin/naksha/model/Naksha.kt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -839,18 +839,6 @@ class Naksha private constructor() {
839839
fun useStorage(config: NakshaStorage): IStorage = _useStorage(config, null)
840840

841841
private fun _useStorage(config: NakshaStorage, forceCreateOrUpgrade: Boolean?): IStorage {
842-
val s = storagesByNumber[config.number]
843-
val s2 = storagesById[config.id]
844-
if (s !== s2) {
845-
throw NakshaException(
846-
ILLEGAL_ARGUMENT,
847-
"The storage-id (${config.id}) and -number (${config.number}) belong to different storages")
848-
}
849-
if (s != null && s.config == config) {
850-
// Only invoke initStorage, when we are forced to do it!
851-
if (forceCreateOrUpgrade == true) s.invokeInitStorage(config, create = true, upgrade = true)
852-
return s
853-
}
854842
lock.acquire().use {
855843
var storage = storagesByNumber[config.number]
856844
val storage2 = storagesById[config.id]
@@ -860,7 +848,10 @@ class Naksha private constructor() {
860848
"The storage-id (${config.id}) and -number (${config.number}) belong to different storages")
861849
}
862850
if (storage != null) {
863-
if (storage.config == config) return storage
851+
if (storage.config == config) {
852+
if (forceCreateOrUpgrade == true) storage.invokeInitStorage(config, create = true, upgrade = true)
853+
return storage
854+
}
864855
storage.invokeShutdownStorage(false)
865856
}
866857
val klass = Platform.klassForName<AbstractStorage<*>>(config.className)

0 commit comments

Comments
 (0)