Skip to content

Commit

Permalink
Fix #8
Browse files Browse the repository at this point in the history
  • Loading branch information
kpgalligan committed Jan 10, 2019
1 parent e7678c0 commit cabde57
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion SQLiter/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
kotlin.code.style=official

GROUP=co.touchlab
VERSION_NAME=0.5.7
VERSION_NAME=0.5.8

STATELY_VERSION=0.5.1
KOTLIN_VERSION=1.3.10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class NativeDatabaseConnection(
}

override fun actualClose(nativePointerArg: Long) {
nativeClose(nativePointerArg) //Call this first, in case it fails
dbManager.decrementConnectionCount()
nativeClose(nativePointerArg)
}

fun migrateIfNeeded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ abstract class NativePointer(nativePointerArg: Long) {
return now
}

/**
* Attempt to run 'actualClose' first. That may fail, in which case we don't want to mark
* the pointer as closed
*/
fun closeNativePointer() = pointerLock.withLock {
val local = nativePointerActual.value
nativePointerActual.value = 0
actualClose(local)
nativePointerActual.value = 0
}

val pointerClosed: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,29 @@ class NativeDatabaseConnectionTest : BaseDatabaseTest(){
assertFails { conn.withStatement(insertSql, goInsert) }
}

@Test
fun testFailedCloseRecall(){
val manager = createDatabaseManager(
DatabaseConfiguration(
name = TEST_DB_NAME, version = 1,
create = { db ->
db.withStatement(TWO_COL) {
execute()

}

}, busyTimeout = 15000
)
)

val conn = manager.createMultiThreadedConnection()
val stmt = conn.createStatement("select * from test")
assertFails { conn.close() }
assertFalse(conn.closed)
stmt.finalizeStatement()
conn.close()
}


private fun threadWait(time: Int, manager: DatabaseManager, block: (DatabaseConnection) -> Unit): Boolean {
return manager.withConnection {
Expand Down

0 comments on commit cabde57

Please sign in to comment.