Skip to content

Commit ab839ef

Browse files
authored
Drain thread pool and increase test time (#386)
* Drain thread pool and increase test time * Fix libsql error Better logs for android launch Use new op-server lock Increase timeouts Change port Change port patch package op-test Debug Get rid of disk cleaner images have bigger disks now Get rid of server update iOS test script Android script Increase timeouts Remove timeouts test ios Background task killer Thread pool fix clean up * test ios script * New libsql fat binary
1 parent 33930ae commit ab839ef

File tree

19 files changed

+1315
-1095
lines changed

19 files changed

+1315
-1095
lines changed

.github/workflows/ci.yml

Lines changed: 74 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Typecheck files
1515
run: yarn typecheck
1616

17-
test-ios:
17+
ios:
1818
runs-on: macos-latest
1919
steps:
2020
- name: Checkout
@@ -56,7 +56,7 @@ jobs:
5656
run: |
5757
./scripts/test-ios.sh
5858
59-
test-ios-embedded:
59+
ios-embedded:
6060
runs-on: macos-latest
6161
steps:
6262
- name: Checkout
@@ -98,7 +98,7 @@ jobs:
9898
run: |
9999
./scripts/test-ios.sh
100100
101-
test-ios-sqlcipher:
101+
ios-sqlcipher:
102102
runs-on: macos-latest
103103
steps:
104104
- name: Checkout
@@ -140,7 +140,7 @@ jobs:
140140
run: |
141141
./scripts/test-ios.sh
142142
143-
test-ios-libsql:
143+
ios-libsql:
144144
runs-on: macos-latest
145145
steps:
146146
- name: Checkout
@@ -149,7 +149,7 @@ jobs:
149149
- name: Xcode Select
150150
run: sudo xcode-select -s /Applications/Xcode_16.4.app
151151

152-
- name: Turn on SQLCipher
152+
- name: Turn on libsql
153153
run: |
154154
node ./scripts/turnOnLibsql.js
155155
@@ -182,25 +182,25 @@ jobs:
182182
run: |
183183
./scripts/test-ios.sh
184184
185-
test-android:
185+
android:
186186
runs-on: ubuntu-latest
187-
timeout-minutes: 20
187+
timeout-minutes: 40
188188
steps:
189-
- name: Free Disk Space (Ubuntu)
190-
uses: insightsengineering/disk-space-reclaimer@v1
191-
with:
192-
# this might remove tools that are actually needed,
193-
# if set to "true" but frees about 6 GB
194-
tools-cache: false
195-
196-
# all of these default to true, but feel free to set to
197-
# "false" if necessary for your workflow
198-
android: false
199-
dotnet: true
200-
haskell: true
201-
large-packages: true
202-
swap-storage: true
203-
docker-images: true
189+
# - name: Free Disk Space (Ubuntu)
190+
# uses: insightsengineering/disk-space-reclaimer@v1
191+
# with:
192+
# # this might remove tools that are actually needed,
193+
# # if set to "true" but frees about 6 GB
194+
# tools-cache: false
195+
196+
# # all of these default to true, but feel free to set to
197+
# # "false" if necessary for your workflow
198+
# android: false
199+
# dotnet: true
200+
# haskell: true
201+
# large-packages: true
202+
# swap-storage: true
203+
# docker-images: true
204204

205205
- name: Checkout
206206
uses: actions/checkout@v4
@@ -236,15 +236,15 @@ jobs:
236236
# ~/.android/adb*
237237
# key: avd-29
238238

239-
- name: create AVD and generate snapshot for caching
240-
# if: steps.avd-cache.outputs.cache-hit != 'true'
241-
uses: reactivecircus/android-emulator-runner@v2
242-
with:
243-
api-level: 29
244-
force-avd-creation: false
245-
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
246-
disable-animations: false
247-
script: echo "Generated AVD snapshot for caching."
239+
# - name: create AVD and generate snapshot for caching
240+
# # if: steps.avd-cache.outputs.cache-hit != 'true'
241+
# uses: reactivecircus/android-emulator-runner@v2
242+
# with:
243+
# api-level: 29
244+
# force-avd-creation: false
245+
# emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
246+
# disable-animations: false
247+
# script: echo "Generated AVD snapshot for caching."
248248

249249
- name: Give execute permissions to script
250250
run: chmod +x ./scripts/test-android.sh
@@ -259,25 +259,33 @@ jobs:
259259
script: |
260260
./scripts/test-android.sh
261261
262-
test-android-sqlcipher:
262+
- name: Upload Android diagnostics
263+
if: failure()
264+
uses: actions/upload-artifact@v4
265+
with:
266+
name: android-logcat-${{ github.job }}
267+
path: example/android-logcat.txt
268+
if-no-files-found: ignore
269+
270+
android-sqlcipher:
263271
runs-on: ubuntu-latest
264-
timeout-minutes: 20
272+
timeout-minutes: 40
265273
steps:
266-
- name: Free Disk Space (Ubuntu)
267-
uses: insightsengineering/disk-space-reclaimer@v1
268-
with:
269-
# this might remove tools that are actually needed,
270-
# if set to "true" but frees about 6 GB
271-
tools-cache: false
272-
273-
# all of these default to true, but feel free to set to
274-
# "false" if necessary for your workflow
275-
android: false
276-
dotnet: true
277-
haskell: true
278-
large-packages: true
279-
swap-storage: true
280-
docker-images: true
274+
# - name: Free Disk Space (Ubuntu)
275+
# uses: insightsengineering/disk-space-reclaimer@v1
276+
# with:
277+
# # this might remove tools that are actually needed,
278+
# # if set to "true" but frees about 6 GB
279+
# tools-cache: false
280+
281+
# # all of these default to true, but feel free to set to
282+
# # "false" if necessary for your workflow
283+
# android: false
284+
# dotnet: true
285+
# haskell: true
286+
# large-packages: true
287+
# swap-storage: true
288+
# docker-images: true
281289
- name: Checkout
282290
uses: actions/checkout@v4
283291

@@ -337,8 +345,17 @@ jobs:
337345
adb shell input keyevent 82
338346
./scripts/test-android.sh
339347
340-
test-android-libsql:
348+
- name: Upload Android diagnostics
349+
if: failure()
350+
uses: actions/upload-artifact@v4
351+
with:
352+
name: android-logcat-${{ github.job }}
353+
path: example/android-logcat.txt
354+
if-no-files-found: ignore
355+
356+
android-libsql:
341357
runs-on: ubuntu-latest
358+
timeout-minutes: 40
342359
env:
343360
TURBO_CACHE_DIR: .turbo/android
344361
steps:
@@ -387,3 +404,11 @@ jobs:
387404
adb wait-for-device
388405
adb shell input keyevent 82
389406
./scripts/test-android.sh
407+
408+
- name: Upload Android diagnostics
409+
if: failure()
410+
uses: actions/upload-artifact@v4
411+
with:
412+
name: android-logcat-${{ github.job }}
413+
path: example/android-logcat.txt
414+
if-no-files-found: ignore

cpp/DBHostObject.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +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);
245+
db = {};
242246
#else
243247
opsqlite_close(db);
248+
db = nullptr;
244249
#endif
245250

246251
return {};
@@ -671,7 +676,13 @@ void DBHostObject::invalidate() {
671676
}
672677

673678
invalidated = true;
674-
thread_pool->restartPool();
679+
// Drain in-flight thread pool work before closing the db handle.
680+
// restartPool() joins threads (waiting for the current task) but then
681+
// needlessly re-creates the pool. waitFinished() is sufficient: it
682+
// blocks until the queue is empty and no worker is busy, then the
683+
// ThreadPool destructor (via shared_ptr release) joins the threads.
684+
thread_pool->waitFinished();
685+
675686
#ifdef OP_SQLITE_USE_LIBSQL
676687
opsqlite_libsql_close(db);
677688
#else

cpp/OPThreadPool.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ void ThreadPool::doWork() {
7474

7575
task = workQueue.front();
7676
workQueue.pop();
77+
++busy;
7778
}
78-
++busy;
7979
task();
80-
--busy;
80+
{
81+
std::lock_guard<std::mutex> g(workQueueMutex);
82+
--busy;
83+
}
84+
workQueueConditionVariable.notify_one();
8185
}
8286
}
8387

example/ios/Podfile.lock

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,6 @@ PODS:
2525
- ReactCommon/turbomodule/core
2626
- ReactNativeDependencies
2727
- Yoga
28-
- OpServer (0.1.5):
29-
- hermes-engine
30-
- RCTRequired
31-
- RCTTypeSafety
32-
- React-Core
33-
- React-Core-prebuilt
34-
- React-debug
35-
- React-Fabric
36-
- React-featureflags
37-
- React-graphics
38-
- React-ImageManager
39-
- React-jsi
40-
- React-NativeModulesApple
41-
- React-RCTFabric
42-
- React-renderercss
43-
- React-rendererdebug
44-
- React-utils
45-
- ReactCodegen
46-
- ReactCommon/turbomodule/bridging
47-
- ReactCommon/turbomodule/core
48-
- ReactNativeDependencies
49-
- Yoga
5028
- RCTDeprecation (0.82.1)
5129
- RCTRequired (0.82.1)
5230
- RCTTypeSafety (0.82.1):
@@ -1803,7 +1781,6 @@ DEPENDENCIES:
18031781
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
18041782
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
18051783
- op-sqlite (from `../..`)
1806-
- "OpServer (from `../node_modules/@op-engineering/op-server`)"
18071784
- RCTDeprecation (from `../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`)
18081785
- RCTRequired (from `../node_modules/react-native/Libraries/Required`)
18091786
- RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`)
@@ -1883,8 +1860,6 @@ EXTERNAL SOURCES:
18831860
:tag: hermes-2025-09-01-RNv0.82.0-265ef62ff3eb7289d17e366664ac0da82303e101
18841861
op-sqlite:
18851862
:path: "../.."
1886-
OpServer:
1887-
:path: "../node_modules/@op-engineering/op-server"
18881863
RCTDeprecation:
18891864
:path: "../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation"
18901865
RCTRequired:
@@ -2027,8 +2002,7 @@ EXTERNAL SOURCES:
20272002
SPEC CHECKSUMS:
20282003
FBLazyVector: 2e5b5553df729e080483373db6f045201ff4e6db
20292004
hermes-engine: 273e30e7fb618279934b0b95ffab60ecedb7acf5
2030-
op-sqlite: a0d8cbee3fc5f8c8b67272c3b07c3b4f07b5b17f
2031-
OpServer: 9b3ebdeeb095950e760e3c39853cd06849421b35
2005+
op-sqlite: e13a2ee437f845fb06f24809f3b2299aa1ef9d0b
20322006
RCTDeprecation: c6b36da89aa26090c8684d29c2868dcca2cd4554
20332007
RCTRequired: 1413a0844770d00fa1f1bb2da4680adfa8698065
20342008
RCTTypeSafety: 354b4bb344998550c45d054ef66913837948f958

example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"ios": "react-native run-ios --scheme='debug' --simulator='iPhone 16 Pro'",
88
"run:ios:unused": "xcodebuild -workspace ios/OPSQLiteExample.xcworkspace -scheme release -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16 Pro' clean build",
99
"run:ios:release": "react-native run-ios --scheme='release' --no-packager",
10+
"postinstall": "patch-package",
1011
"start": "react-native start",
1112
"pods": "cd ios && bundle exec pod install && rm -f .xcode.env.local",
1213
"pods:nuke": "cd ios && rm -rf Pods && rm -rf Podfile.lock && bundle exec pod install",
@@ -15,7 +16,6 @@
1516
"build:ios": "cd ios && xcodebuild -workspace OPSQLiteExample.xcworkspace -scheme debug -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO"
1617
},
1718
"dependencies": {
18-
"@op-engineering/op-server": "^0.1.5",
1919
"@op-engineering/op-test": "^0.2.5",
2020
"chance": "^1.1.9",
2121
"clsx": "^2.0.0",
@@ -36,6 +36,7 @@
3636
"@react-native/typescript-config": "0.81.5",
3737
"@types/chance": "^1.1.7",
3838
"@types/react": "^19.1.1",
39+
"patch-package": "^8.0.1",
3940
"react-native-builder-bob": "^0.40.13",
4041
"react-native-monorepo-config": "^0.1.9",
4142
"react-native-restart": "^0.0.27",

0 commit comments

Comments
 (0)