Skip to content

[JVM Windows] Process shutdown bug #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.0.0-BETA29 (unreleased)

* Fix potential race condition between jobs in `connect()` and `disconnect()`.
* [JVM Windows] Fixed PowerSync Extension temporary file deletion error on process shutdown.
* [iOS] Fixed issue where automatic driver migrations would fail with the error:
```
Sqlite operation failure database is locked attempted to run migration and failed. closing connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public actual class DatabaseDriverFactory {
}

public companion object {
private val powersyncExtension: String = extractLib("powersync").toString()
private val powersyncExtension: String = extractLib("powersync")
}
}
23 changes: 9 additions & 14 deletions core/src/jvmMain/kotlin/com/powersync/ExtractLib.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.powersync

import java.nio.file.Path
import kotlin.io.path.createTempFile
import kotlin.io.path.deleteIfExists
import kotlin.io.path.outputStream
import java.io.File

private class R

internal fun extractLib(fileName: String): Path {
internal fun extractLib(fileName: String): String {
val os = System.getProperty("os.name").lowercase()
val (prefix, extension) =
when {
Expand All @@ -26,14 +23,12 @@ internal fun extractLib(fileName: String): Path {

val path = "/$prefix${fileName}_$arch.$extension"

val tmpPath = createTempFile("$prefix$fileName", ".$extension")
Runtime.getRuntime().addShutdownHook(Thread { tmpPath.deleteIfExists() })
val resourceURI =
(R::class.java.getResource(path) ?: error("Resource $path not found"))

(R::class.java.getResourceAsStream(path) ?: error("Resource $path not found")).use { input ->
tmpPath.outputStream().use { output ->
input.copyTo(output)
}
}

return tmpPath
// Wrapping the above in a File handle resolves the URI to a path usable by SQLite.
// This is particularly relevant on Windows.
// On Windows [resourceURI.path] starts with a `/`, e.g. `/c:/...`. SQLite does not load this path correctly.
// The wrapping here transforms the path to `c:/...` which does load correctly.
return File(resourceURI.path).path.toString()
}