Skip to content

Commit a559a5e

Browse files
committed
Prevent race condition to crash the app when the module is invalidated and db has been closed
1 parent 33dee22 commit a559a5e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cpp/DBHostObject.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ void DBHostObject::create_jsi_functions() {
238238
});
239239

240240
function_map["close"] = HOSTFN("close") {
241+
invalidated = true;
242+
241243
#ifdef OP_SQLITE_USE_LIBSQL
242244
opsqlite_libsql_close(db);
243245
#else
@@ -248,6 +250,8 @@ void DBHostObject::create_jsi_functions() {
248250
});
249251

250252
function_map["delete"] = HOSTFN("delete") {
253+
invalidated = true;
254+
251255
std::string path = std::string(base_path);
252256

253257
if (count == 1) {
@@ -808,6 +812,10 @@ void DBHostObject::set(jsi::Runtime &_rt, const jsi::PropNameID &name,
808812
}
809813

810814
void DBHostObject::invalidate() {
815+
if(invalidated) {
816+
return;
817+
}
818+
811819
invalidated = true;
812820
_thread_pool->restartPool();
813821
#ifdef OP_SQLITE_USE_LIBSQL

0 commit comments

Comments
 (0)