diff --git a/CHANGELOG.md b/CHANGELOG.md index 74797e7..7db6a01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [1.4.3] - 2026-11-16 + +This release adds one C function, `sqlitejs_cancel_all()`, for a host that has no other way to stop +JavaScript that does not come back. Nothing changes for an application that never calls it: SQL and +JavaScript behave exactly as on 1.4.2 until a cancel arrives. + +### Added + +- **`sqlitejs_cancel_all()` stops all JavaScript running now, in every connection.** Each call into JavaScript fails with an "interrupted" error, even code that catches every exception, and JavaScript that begins afterwards runs normally. It is safe to call from any thread, and it works on every SQLite version, including those before 3.41.0 where `sqlite3_interrupt()` cannot reach JavaScript at all. It exists for hosts whose own cancelling cannot: Android cancels a query with a progress handler, which SQLite never calls while a function is running, and Room 2.7 and later pass no cancellation signal at all, so a runaway function could previously only be stopped by killing the process. **The connection whose JavaScript is stopped is interrupted as well**, as `sqlite3_interrupt()` does it, because a collation cannot report an error and its sort would otherwise go on calling JavaScript, each call beginning after the cancel; so any other statement that connection has in progress fails with SQLITE_INTERRUPT too, and `sqlite3_is_interrupted()` stays true for it until the connection next prepares or steps a statement with none of its own still running. The function is declared in `sqlitejs.h` and exported from the Windows DLL. +- **A result set the cancelled call left open reads on as "interrupted"**, where 1.4.2 says it was closed when the call that created it returned. Ending such a result set runs the `final` of the window or aggregate function its statement was computing, and those finals belong to the call that is being cancelled: one that never ends is stopped, and its statement fails with an interrupt, rather than hanging the statement for good on SQLite before 3.41.0. A short `final` can still run to its end before the engine's next interrupt check. +- **A cancel never stops the JavaScript the extension itself runs to set a connection up**, so a connection opening while cancels are in flight still comes up complete: neither the code run while the extension loads nor the functions `js_init_table(1)` restores from the `js_functions` table are cancelled. Only that work is exempt — JavaScript it reaches through SQL is a call of its own and is cancelled — and on SQLite 3.41.0 and later `sqlite3_interrupt()` still stops setup JavaScript that never ends. + ## [1.4.2] - 2026-11-13 One change in this release can alter the behavior of JavaScript that works on 1.4.1: a `db.exec()` diff --git a/Makefile b/Makefile index 7384adb..093d491 100644 --- a/Makefile +++ b/Makefile @@ -124,6 +124,7 @@ ifeq ($(PLATFORM),windows) @echo " sqlite3_js_init" >> $@ @echo " sqlitejs_version" >> $@ @echo " quickjs_version" >> $@ + @echo " sqlitejs_cancel_all" >> $@ endif # Clean up diff --git a/src/sqlitejs.c b/src/sqlitejs.c index 26af849..538f4f2 100644 --- a/src/sqlitejs.c +++ b/src/sqlitejs.c @@ -70,9 +70,13 @@ typedef struct { size_t mem_peak; // the most in use since the last result or error size_t stack_size; // in bytes, 0 for no check: see js_set_max_stack_size() int depth; // calls into JavaScript in progress: see js_enter() + unsigned cancel_epoch; // js_cancel_epoch when the outermost call began + int setup_depth; // depth of a call that sets the connection up, 0 for none: see js_interrupt_handler() + bool check_interrupted; // sqlite3_is_interrupted() is available struct rowset *rowsets; // result sets not yet freed: see js_end_rowsets() int orphans; // of those, the ones whose JavaScript object is gone bool ending_rowsets; // js_end_rowsets() is running + unsigned end_pass; // js_end_rowsets() passes that ended every result set } globaljs_context; typedef struct { @@ -115,6 +119,7 @@ typedef struct rowset { bool ended; // ended by js_end_rowsets(): reading on throws bool interrupted; // and an interrupt is why: reading on throws "interrupted" bool orphaned; // its JavaScript object is gone: see js_rowset_finalizer() + unsigned end_pass; // the js_end_rowsets() pass that ended it struct rowset *prev, *next; // in the connection's list: see js_end_rowsets() } rowset; @@ -270,9 +275,12 @@ static void js_rowset_finalizer(JSRuntime *rt, JSValue val) { // computing, whose js_leave() comes back here and whose garbage collection can free result sets // of the list. So each statement is taken from its result set before it is finalized, the list // is walked again from its head after each one, and a nested call does nothing. +static unsigned js_cancel_epoch_load (void); + static void js_end_rowsets (globaljs_context *js, bool all, bool interrupted) { if (js->ending_rowsets) return; js->ending_rowsets = true; + unsigned pass = all ? ++js->end_pass : 0; for (;;) { rowset *rs = js->rowsets; while (rs && !(rs->orphaned || (all && rs->vm))) rs = rs->next; @@ -289,10 +297,17 @@ static void js_end_rowsets (globaljs_context *js, bool all, bool interrupted) { } else { rs->vm = NULL; rs->ended = true; + rs->end_pass = pass; if (interrupted) rs->interrupted = true; } if (vm) sqlite3_finalize(vm); } + // A cancel that landed while the finals ran stopped them, as one before the call returned + // would have: the result sets this pass ended read on as interrupted too. Nothing runs + // JavaScript here, so the list holds only result sets that are still allocated. + if (all && !interrupted && (js->cancel_epoch != js_cancel_epoch_load())) { + for (rowset *r = js->rowsets; r; r = r->next) if (r->ended && (r->end_pass == pass)) r->interrupted = true; + } js->ending_rowsets = false; } @@ -325,6 +340,32 @@ static void js_collect_below_limit (globaljs_context *js) { js_keep_gc_below_limit(js); } +// Bumped by sqlitejs_cancel_all(): JavaScript that began before stops, as if interrupted. +static unsigned js_cancel_epoch; + +static unsigned js_cancel_epoch_load (void) { +#if defined(__clang__) || defined(__GNUC__) + return __atomic_load_n(&js_cancel_epoch, __ATOMIC_ACQUIRE); +#else + return *(volatile unsigned *)&js_cancel_epoch; +#endif +} + +// Stops all JavaScript that is running now, in every connection: each call fails with an +// "interrupted" error, and the connection it was running on is interrupted, so every statement +// that connection has in progress fails with SQLITE_INTERRUPT too (see js_interrupt_handler). +// JavaScript that begins afterwards runs normally, and the JavaScript the extension itself runs +// to set a connection up is never stopped. Safe from any thread. +// For hosts whose own cancelling cannot reach JavaScript: Android cancels a query with a +// progress handler, which SQLite never calls while a JavaScript function runs. +void sqlitejs_cancel_all (void) { +#if defined(__clang__) || defined(__GNUC__) + __atomic_add_fetch(&js_cancel_epoch, 1, __ATOMIC_RELEASE); +#else + (*(volatile unsigned *)&js_cancel_epoch)++; +#endif +} + // QuickJS calls this from time to time while it runs code. A non-zero result stops the code // with an uncatchable "interrupted" error, so sqlite3_interrupt() (Ctrl-C in the sqlite3 shell, // a cancelled query in an app) also stops JavaScript that never returns to SQLite. @@ -332,7 +373,22 @@ static int js_interrupt_handler (JSRuntime *rt, void *opaque) { UNUSED(rt); globaljs_context *js = (globaljs_context *)opaque; js_keep_gc_below_limit(js); - return (js->db != NULL) && sqlite3_is_interrupted(js->db); + // Only a call (see js_enter) is cancelled, and never the JavaScript the extension itself runs + // to set a connection up: while it loads the extension (globaljs_init, depth 0), and while + // js_init_table(1) restores the functions of the js_functions table (js_create_common, which + // records its depth in setup_depth). Stopping either leaves the connection short of what an + // app expects of it: a cancel during the first made it fail to load, and one during the second + // left it without its stored functions, each reported only by a statement an app need not look + // at. Like the depth 0 exemption, this one covers that call alone: JavaScript the loading code + // runs through SQL is a call of its own, at a greater depth, and is cancelled. And on SQLite + // 3.41 and later sqlite3_interrupt() still stops setup JavaScript that never ends, as always. + if ((js->depth > 0) && (js->depth != js->setup_depth) && (js->cancel_epoch != js_cancel_epoch_load())) { + // The statement is interrupted too: a collation cannot report an error, so the + // statement would go on calling JavaScript, each call beginning after the cancel. + if (js->db) sqlite3_interrupt(js->db); + return 1; + } + return js->check_interrupted && (js->db != NULL) && sqlite3_is_interrupted(js->db); } // The most memory, in bytes, the JavaScript runtime of a connection may allocate until @@ -542,6 +598,10 @@ static bool js_stack_room (size_t *room) { // runs JavaScript) is on the same thread and keeps the outer call's limit. static void js_enter (globaljs_context *js) { if (js->depth++ > 0) return; + // The finals that ending a call's result sets runs (see js_leave) belong to that call: they keep + // its epoch, so a cancel during the call or during the ending stops them, as it would have + // stopped the call. Before SQLite 3.41 nothing else would stop one that never ends. + if (!js->ending_rowsets) js->cancel_epoch = js_cancel_epoch_load(); JS_UpdateStackTop(js->runtime); // A thread with less room than SQLITE_JS_STACK_MIN keeps it too: JavaScript there then fails // with "Maximum call stack size exceeded" rather than running past the end of the stack. A @@ -556,6 +616,8 @@ static void js_enter (globaljs_context *js) { static void js_leave (globaljs_context *js) { if (--js->depth > 0) return; if (!js->rowsets) return; + // A cancel (sqlitejs_cancel_all) is not seen here: js_end_rowsets() marks its result sets + // interrupted itself, which is the only way they read so before SQLite 3.41. bool interrupted = (sqlite3_libversion_number() >= 3041000) && js->db && sqlite3_is_interrupted(js->db); js_end_rowsets(js, true, interrupted); } @@ -577,8 +639,9 @@ static globaljs_context *globaljs_init (sqlite3 *db) { //JS_SetMaxStackSize(rt, 10 * 1024); // sqlite3_is_interrupted() is new in SQLite 3.41.0: an older library has no such entry - // in its sqlite3_api_routines, so JavaScript cannot be interrupted there - if (sqlite3_libversion_number() >= 3041000) JS_SetInterruptHandler(rt, js_interrupt_handler, js); + // in its sqlite3_api_routines, so JavaScript cannot be interrupted there, only cancelled + js->check_interrupted = (sqlite3_libversion_number() >= 3041000); + JS_SetInterruptHandler(rt, js_interrupt_handler, js); // the default stack size must fit in the stack of the thread that loads the extension: Windows // gives a main thread 1 MB, and apps often give their threads no more @@ -900,6 +963,7 @@ static JSValue js_sqlite_exec (JSContext *ctx, sqlite3 *db, const char *sql, int rs->vm = vm; rs->ncols = sqlite3_column_count(vm); rs->ended = false; + rs->end_pass = 0; rs->interrupted = false; rs->orphaned = false; rs->prev = rs->next = NULL; @@ -1612,7 +1676,15 @@ static bool js_create_function (sqlite3_context *context, const char *type, cons bool js_create_common (sqlite3_context *context, const char *type, const char *name, const char *init_code, const char *step_code, const char *final_code, const char *value_code, const char *inverse_code, bool is_load) { globaljs_context *js = (globaljs_context *)sqlite3_user_data(context); js_enter(js); + // Restoring a function of the js_functions table (is_load) sets the connection up, as loading + // the extension does, so sqlitejs_cancel_all() does not stop it: see js_interrupt_handler(). + // Only this call is exempt, not JavaScript it runs through SQL, which is a call of its own at + // a greater depth. The previous value is kept for an is_load that a stored function's own code + // reaches through js_init_table(). + int setup_depth = js->setup_depth; + if (is_load) js->setup_depth = js->depth; bool ok = js_create_function(context, type, name, init_code, step_code, final_code, value_code, inverse_code, is_load); + js->setup_depth = setup_depth; js_leave(js); return ok; } diff --git a/src/sqlitejs.h b/src/sqlitejs.h index fb0172d..9d54f92 100644 --- a/src/sqlitejs.h +++ b/src/sqlitejs.h @@ -16,10 +16,22 @@ #include "sqlite3.h" #endif -#define SQLITE_JS_VERSION "1.4.2" +#define SQLITE_JS_VERSION "1.4.3" int sqlite3_js_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi); const char *sqlitejs_version (void); const char *quickjs_version (void); +// Stops all JavaScript now running, in every connection: each call into JavaScript fails with an +// "interrupted" error, and a result set it leaves open reads on as interrupted. Safe to call from +// any thread. +// It stops only JavaScript already running: calls that begin afterwards are not affected, and +// neither is the JavaScript the extension itself runs to set a connection up, while it loads the +// extension and while js_init_table(1) restores the functions of the js_functions table. +// A connection whose JavaScript is stopped is also interrupted, as sqlite3_interrupt() does it: +// a collation cannot report an error, so without that its sort would go on calling JavaScript. +// So any other statement that connection has in progress fails with SQLITE_INTERRUPT as well, +// and sqlite3_is_interrupted() stays true for it until the connection next prepares or steps a +// statement with none of its own still running, as after any sqlite3_interrupt(). +void sqlitejs_cancel_all (void); #endif diff --git a/test/main.c b/test/main.c index 8cc3706..db9fcaa 100644 --- a/test/main.c +++ b/test/main.c @@ -1047,6 +1047,211 @@ int test_memory_limit (void) { return rc; } +// MARK: - Cancel all - + +// Set by started(), an SQL function that the JavaScript under test calls before it spins, so +// that the worker cancels only JavaScript that is running: a cancel that came first would not +// stop it +static int test_js_started; + +static void test_started (sqlite3_context *context, int argc, sqlite3_value **argv) { + (void)argc; (void)argv; + __atomic_store_n(&test_js_started, 1, __ATOMIC_RELEASE); + sqlite3_result_null(context); +} + +// Cancels from inside the statement under test: the cancel lands before the call returns, but +// after its JavaScript last checked for one +static void test_cancel_now (sqlite3_context *context, int argc, sqlite3_value **argv) { + (void)argc; (void)argv; + sqlitejs_cancel_all(); + sqlite3_result_null(context); +} + +static void *test_cancel_all_worker (void *ptr) { + (void)ptr; + // wait for the JavaScript to start, for at most 10 s; cancelling before it starts would + // leave it running, so a JavaScript that has not started by then fails the test here + for (int i = 0; i < 1000 && !__atomic_load_n(&test_js_started, __ATOMIC_ACQUIRE); ++i) usleep(10 * 1000); + if (!__atomic_load_n(&test_js_started, __ATOMIC_ACQUIRE)) { + printf("FAIL: the JavaScript under test did not start in 10 seconds\n"); + fflush(stdout); + abort(); + } + sqlitejs_cancel_all(); + return NULL; +} + +static int test_cancelling; + +static void *test_cancel_loop (void *ptr) { + (void)ptr; + while (__atomic_load_n(&test_cancelling, __ATOMIC_ACQUIRE)) sqlitejs_cancel_all(); + return NULL; +} + +// Opens connections while another thread cancels without pause. Setting up a connection runs +// JavaScript of its own, and a cancel that stopped it made the connection fail to load. +static int test_cancel_during_open (void) { + pthread_t thread; + __atomic_store_n(&test_cancelling, 1, __ATOMIC_RELEASE); + if (pthread_create(&thread, NULL, test_cancel_loop, NULL) != 0) return SQLITE_ERROR; + int rc = SQLITE_OK; + for (int i = 0; (i < 200) && (rc == SQLITE_OK); ++i) { + sqlite3 *db = NULL; + rc = test_open(&db); + if (rc != SQLITE_OK) printf("FAIL: connection %d did not open while another thread cancelled: %s\n", i, db ? sqlite3_errmsg(db) : sqlite3_errstr(rc)); + if (db) sqlite3_close(db); + } + __atomic_store_n(&test_cancelling, 0, __ATOMIC_RELEASE); + pthread_join(thread, NULL); + return rc; +} + +// Opens a database file with the extension loaded, as test_open does an in-memory one. +static int test_open_path (sqlite3 **db, const char *path) { + int rc = sqlite3_open(path, db); + if (rc != SQLITE_OK) return rc; + + #if JS_LOAD_EMBEDDED + return sqlite3_js_init(*db, NULL, NULL); + #else + rc = sqlite3_enable_load_extension(*db, 1); + if (rc != SQLITE_OK) return rc; + return db_exec(*db, "SELECT load_extension('./dist/js');"); + #endif +} + +// Restores the functions of the js_functions table while another thread cancels without pause. +// Loading one runs its JavaScript, and a cancel that stopped it left the connection without the +// function: js_init_table(1) failed with "interrupted", which an app that does not look at the +// result of that statement never sees, so a pooled connection came up unable to run a query of +// its own. The init code here is long enough to reach one of QuickJS's interrupt checks, so +// every load was stopped without the exemption; a short one could finish before the first check. +static int test_cancel_during_load (void) { + const char *path = "js_cancel_load.sqlite"; + remove(path); + + sqlite3 *db = NULL; + int rc = test_open_path(&db, path); + if (rc == SQLITE_OK) rc = check_query(db, "SELECT js_init_table();", "0"); + if (rc == SQLITE_OK) rc = check_query(db, "SELECT js_create_aggregate('slow_total', 'var warm = 0; for (var i = 0; i < 1000000; i++) warm += i; total = 0;', '(function (args) { total += args[0]; })', '(function () { return total; })');", "0"); + if (db) sqlite3_close(db); + if (rc != SQLITE_OK) { remove(path); return rc; } + + pthread_t thread; + __atomic_store_n(&test_cancelling, 1, __ATOMIC_RELEASE); + if (pthread_create(&thread, NULL, test_cancel_loop, NULL) != 0) { remove(path); return SQLITE_ERROR; } + for (int i = 0; (i < 10) && (rc == SQLITE_OK); ++i) { + db = NULL; + rc = test_open_path(&db, path); + if (rc == SQLITE_OK) { + rc = check_query(db, "SELECT js_init_table(1);", "0"); + if (rc != SQLITE_OK) printf("FAIL: connection %d loaded none of its stored functions while another thread cancelled: %s\n", i, sqlite3_errmsg(db)); + } + if (db) sqlite3_close(db); + } + __atomic_store_n(&test_cancelling, 0, __ATOMIC_RELEASE); + pthread_join(thread, NULL); + + // a function loaded that way is the one the table holds, and runs once the cancels stop + if (rc == SQLITE_OK) { + db = NULL; + rc = test_open_path(&db, path); + if (rc == SQLITE_OK) rc = check_query(db, "SELECT js_init_table(1);", "0"); + if (rc == SQLITE_OK) rc = check_query(db, "SELECT slow_total(column1) FROM (VALUES (1), (2), (3));", "6"); + if (db) sqlite3_close(db); + } + + remove(path); + return rc; +} + +// sqlitejs_cancel_all() stops the JavaScript running in every connection, as Android's own +// cancelling (a progress handler, which SQLite never calls while a function runs) cannot. +int test_cancel_all (void) { + sqlite3 *db = NULL, *db2 = NULL; + pthread_t thread; + + int seconds = 30; + pthread_t watchdog; + test_watchdog_stop = 0; + bool watching = (pthread_create(&watchdog, NULL, test_watchdog, &seconds) == 0); + + int rc = test_open(&db); + if (rc != SQLITE_OK) goto abort_test; + rc = sqlite3_create_function(db, "started", 0, SQLITE_UTF8, NULL, test_started, NULL, NULL); + if (rc != SQLITE_OK) goto abort_test; + rc = db_exec(db, "SELECT js_create_scalar('spin', '(function (args) { db.exec(\"SELECT started()\").next(); for (;;) { try { while (true) {} } catch (e) {} } })');"); + if (rc != SQLITE_OK) goto abort_test; + + // JavaScript running now stops, even code that catches every exception + test_js_started = 0; + if (pthread_create(&thread, NULL, test_cancel_all_worker, NULL) != 0) { rc = SQLITE_ERROR; goto abort_test; } + rc = check_error(db, "SELECT spin();", "interrupted"); + pthread_join(thread, NULL); + if (rc != SQLITE_OK) goto abort_test; + + // a collation cannot report an error, so its statement is interrupted too: otherwise the sort + // would go on calling it, and each call, begun after the cancel, would run + rc = db_exec(db, "SELECT js_create_collation('spin_collation', '(function (a, b) { db.exec(\"SELECT started()\").next(); for (;;) {} })');"); + if (rc != SQLITE_OK) goto abort_test; + test_js_started = 0; + if (pthread_create(&thread, NULL, test_cancel_all_worker, NULL) != 0) { rc = SQLITE_ERROR; goto abort_test; } + rc = check_error(db, "SELECT column1 FROM (VALUES ('a'), ('b'), ('c')) ORDER BY column1 COLLATE spin_collation;", "interrupted"); + pthread_join(thread, NULL); + if (rc != SQLITE_OK) goto abort_test; + + // When a call returns, ending its result sets runs the finals of the window functions they + // were computing, and those finals belong to the call. A cancel that lands while they are + // ended stops every one, and the result sets read on as interrupted: here the newer result + // set's final starts the cancel and never ends, then the older one's never ends. + rc = db_exec(db, "SELECT js_create_window('loop_final', 'total = 0;', '(function (args) { total += args[0]; })', '(function () { while (true) {} })', '(function () { return total; })', '(function (args) { total -= args[0]; })');"); + if (rc != SQLITE_OK) goto abort_test; + rc = db_exec(db, "SELECT js_create_window('start_final', 'total = 0;', '(function (args) { total += args[0]; })', '(function () { db.exec(\"SELECT started()\").next(); while (true) {} })', '(function () { return total; })', '(function (args) { total -= args[0]; })');"); + if (rc != SQLITE_OK) goto abort_test; + test_js_started = 0; + if (pthread_create(&thread, NULL, test_cancel_all_worker, NULL) != 0) { rc = SQLITE_ERROR; goto abort_test; } + rc = check_error(db, "SELECT js_eval('globalThis.a = db.exec(\"SELECT loop_final(column1) OVER (ORDER BY column1) FROM (VALUES (1), (2), (3))\"); a.next(); globalThis.b = db.exec(\"SELECT start_final(column1) OVER (ORDER BY column1) FROM (VALUES (1), (2), (3))\"); b.next(); 0');", "interrupted"); + pthread_join(thread, NULL); + if (rc != SQLITE_OK) goto abort_test; + rc = check_query(db, "SELECT js_eval('[a, b].map((r) => { try { r.next(); return \"open\"; } catch (e) { return e.message; } }).join()');", "interrupted,interrupted"); + if (rc != SQLITE_OK) goto abort_test; + + // A cancel that lands as a call returns, after its JavaScript last checked for one, stops the + // final that ending its result set runs, and the call fails rather than skipping the final + rc = sqlite3_create_function(db, "cancel_now", 0, SQLITE_UTF8, NULL, test_cancel_now, NULL, NULL); + if (rc != SQLITE_OK) goto abort_test; + rc = db_exec(db, "CREATE TABLE ran(x); SELECT js_create_window('long_final', 'total = 0;', '(function (args) { total += args[0]; })', '(function () { let s = 0; for (let i = 0; i < 20000000; i++) s += i; db.exec(\"INSERT INTO ran VALUES (1)\").next(); return total; })', '(function () { return total; })', '(function (args) { total -= args[0]; })');"); + if (rc != SQLITE_OK) goto abort_test; + rc = check_error(db, "SELECT js_eval('globalThis.c = db.exec(\"SELECT long_final(column1) OVER (ORDER BY column1) FROM (VALUES (1), (2), (3))\"); c.next(); db.exec(\"SELECT cancel_now()\").next(); 0');", "interrupted"); + if (rc != SQLITE_OK) goto abort_test; + rc = check_query(db, "SELECT count(*) FROM ran;", "0"); + if (rc != SQLITE_OK) goto abort_test; + + // JavaScript that begins afterwards runs normally, on this connection and on a new one + rc = check_query(db, "SELECT js_eval('1 + 1');", "2"); + if (rc != SQLITE_OK) goto abort_test; + rc = test_open(&db2); + if (rc != SQLITE_OK) goto abort_test; + rc = check_query(db2, "SELECT js_eval('2 + 2');", "4"); + if (rc != SQLITE_OK) goto abort_test; + + // and a connection opened while cancels go on still loads the extension, and still restores + // the functions of its js_functions table + rc = test_cancel_during_open(); + if (rc != SQLITE_OK) goto abort_test; + rc = test_cancel_during_load(); + +abort_test: + test_watchdog_stop = 1; + if (watching) pthread_join(watchdog, NULL); + if (rc != SQLITE_OK && db) printf("Error: %s\n", sqlite3_errmsg(db)); + if (db) sqlite3_close(db); + if (db2) sqlite3_close(db2); + return rc; +} + // MARK: - Stack size - int test_stack_size (void) { @@ -1276,6 +1481,7 @@ int main (void) { result += test_report("Serialization 3", test_serialization(DB_PATH, true, 3)); // load the new implementations result += test_report("Thread", test_thread()); result += test_report("Interrupt", test_interrupt()); + result += test_report("Cancel all", test_cancel_all()); result += test_report("Direct only", test_direct_only()); result += test_report("Aggregate errors", test_aggregate_errors()); result += test_report("Exec errors", test_exec_errors());