File tree Expand file tree Collapse file tree 3 files changed +24
-14
lines changed
Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Original file line number Diff line number Diff line change @@ -236,12 +236,16 @@ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
236236
237237 function_map[" close" ] = HFN (this ) {
238238 invalidated = true ;
239-
239+ // Drain any in-flight async queries before closing the db handle.
240+ // Without this, a queued/running execute() on the thread pool may
241+ // dereference the freed sqlite3* pointer → heap corruption / SIGABRT.
242+ thread_pool->waitFinished ();
240243#ifdef OP_SQLITE_USE_LIBSQL
241244 opsqlite_libsql_close (db);
242245#else
243246 opsqlite_close (db);
244247#endif
248+ db = nullptr ;
245249
246250 return {};
247251 });
@@ -671,7 +675,13 @@ void DBHostObject::invalidate() {
671675 }
672676
673677 invalidated = true ;
674- thread_pool->restartPool ();
678+ // Drain in-flight thread pool work before closing the db handle.
679+ // restartPool() joins threads (waiting for the current task) but then
680+ // needlessly re-creates the pool. waitFinished() is sufficient: it
681+ // blocks until the queue is empty and no worker is busy, then the
682+ // ThreadPool destructor (via shared_ptr release) joins the threads.
683+ thread_pool->waitFinished ();
684+
675685#ifdef OP_SQLITE_USE_LIBSQL
676686 opsqlite_libsql_close (db);
677687#else
Original file line number Diff line number Diff line change 77} from '@op-engineering/op-test' ;
88import './tests' ; // import all tests to register them
99import { SafeAreaProvider , SafeAreaView } from 'react-native-safe-area-context' ;
10- import { performanceTest } from './performance_test' ;
10+ // import {performanceTest} from './performance_test';
1111import { StyleSheet , Text , View } from 'react-native' ;
1212import { open } from '@op-engineering/op-sqlite' ;
1313
@@ -35,15 +35,15 @@ export default function App() {
3535 setServerResults ( false ) ;
3636 }
3737
38- setTimeout ( ( ) => {
39- try {
40- global ?. gc ?.( ) ;
41- let perfRes = performanceTest ( ) ;
42- setPerfResult ( perfRes ) ;
43- } catch ( e ) {
44- // intentionally left blank
45- }
46- } , 1000 ) ;
38+ // setTimeout(() => {
39+ // try {
40+ // global?.gc?.();
41+ // let perfRes = performanceTest();
42+ // setPerfResult(perfRes);
43+ // } catch (e) {
44+ // // intentionally left blank
45+ // }
46+ // }, 1000);
4747 } ;
4848
4949 work ( ) ;
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ const http = require('http');
22
33async function pollInAppServer ( ) {
44 const startTime = Date . now ( ) ;
5- const maxDuration = 5 * 60 * 1000 ; // 3 minutes - tests can take time on CI
6- const pollInterval = 5000 ; //
5+ const maxDuration = 10 * 60 * 1000 ;
6+ const pollInterval = 10000 ; //
77
88 // Do an initial ping into the server
99
You can’t perform that action at this time.
0 commit comments