diff --git a/CHANGELOG.md b/CHANGELOG.md index 45552a2..a62fccd 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,8 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [2020-06-14] Removed old cache subdirectory migration system by [@carbotaniuman]. ### Fixed -- [2020-06-15] Fixed tokenized data-saver parser not working by [@lflare]. - [2020-06-14] Switched cache metadata over to a MySql instance [@carbotaniuman]. +- [2020-06-15] Fixed tokenized data-saver parser not working by [@lflare]. +- [2020-06-15] Properly synchronised sqlite3 handler across threads by [@lflare]. ## [1.0.0-RC16] - 2020-06-14 ### Added diff --git a/src/main/kotlin/mdnet/base/server/ImageServer.kt b/src/main/kotlin/mdnet/base/server/ImageServer.kt index 6414298..628a254 100644 --- a/src/main/kotlin/mdnet/base/server/ImageServer.kt +++ b/src/main/kotlin/mdnet/base/server/ImageServer.kt @@ -77,8 +77,10 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi val imageId = printHexString(rc4Bytes) val snapshot = cache.getUnsafe(imageId.toCacheId()) - val imageDatum = transaction(database) { - ImageDatum.findById(imageId) + val imageDatum = synchronized(database) { + transaction(database) { + ImageDatum.findById(imageId) + } } if (snapshot != null && imageDatum != null) { @@ -96,8 +98,10 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi if (LOGGER.isWarnEnabled) { LOGGER.warn("Deleting DB entry for $sanitizedUri without corresponding file") } - transaction(database) { - imageDatum.delete() + synchronized(database) { + transaction(database) { + imageDatum.delete() + } } } @@ -174,10 +178,12 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi LOGGER.trace("Request for $sanitizedUri is being cached and served") } - transaction(database) { - ImageDatum.new(imageId) { - this.contentType = contentType - this.lastModified = lastModified + synchronized(database) { + transaction(database) { + ImageDatum.new(imageId) { + this.contentType = contentType + this.lastModified = lastModified + } } }