Skip to content

Commit 1a14c43

Browse files
committed
fix(native): lock database
- call the runnable even if there is no mutex found
1 parent d5b47e3 commit 1a14c43

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

native/rust/src/modules/sqlite_hook.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,24 @@ pub fn lock_database(mut env: JNIEnv, _: *mut c_void, filename: JString, runnabl
5050
let database_filename = get_jni_string(&mut env, filename).expect("Failed to get database filename");
5151
let mutex = SQLITE3_MUTEX_MAP.lock().unwrap().get(&database_filename).map(|mutex| *mutex);
5252

53+
let call_runnable = || {
54+
env.call_method(runnable, "run", "()V", &[]).expect("Failed to call run method");
55+
};
56+
5357
if let Some(mut mutex) = mutex {
5458
if unsafe { libc::pthread_mutex_lock(addr_of_mut!(mutex)) } != 0 {
5559
error!("pthread_mutex_lock failed");
5660
return;
5761
}
5862

59-
env.call_method(runnable, "run", "()V", &[]).expect("Failed to call run method");
63+
call_runnable();
6064

6165
if unsafe { libc::pthread_mutex_unlock(addr_of_mut!(mutex)) } != 0 {
6266
error!("pthread_mutex_unlock failed");
6367
}
6468
} else {
6569
warn!("No mutex found for database: {}", database_filename);
70+
call_runnable();
6671
}
6772
}
6873

0 commit comments

Comments
 (0)