Repository navigation
The core's tests no longer crash at exit: they wait for databases still closing - #197
Merged
Merged
Conversation
sqlx closes a dropped connection on its worker thread after the drop returns, so the last tests' databases could still be closing as the test binary exited, while SQLCipher's exit handler freed what an encrypted one's close uses. A test-only exit handler, registered after SQLCipher's, runs first and waits for sqlx's workers to end.
Owner
Author
|
Review (code-reviewer on
Suggestions:
Re-run after the changes: |
This was referenced Nov 29, 2026
The desktop tests no longer crash at exit with a core still running or a database still closing
#310
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
New test-only module
sig-core/src/test_exit.rs. Before the first encrypted database opens (ProjectionDb::openwith a key, andactor::sqlite_optionsfor presage's store), it registers an exit handler. At exit, the handler waits until sqlx's worker threads have ended, 5 s at most. Each worker ends once its connection has closed.proc_pidinfo./proc/self/task.It's all
#[cfg(test)], so the app's code doesn't change.Why
cargo test -p sig-coresometimes ended with SIGSEGV aftertest result: ok. There are 22 crash reports, all with the same stack. sqlx closes a dropped connection on its worker thread after the drop returns, so the last tests' databases can still be closing when the binary exits. SQLCipher's exit handler then frees its private heap and providers while an encrypted database's close still uses them (sqlcipher_codec_ctx_free→sqlcipher_free).Exit handlers run newest first, so a handler registered after SQLCipher's runs before it. One catch, found by a crash with the first version: SQLite runs SQLCipher's init (which registers its handler) after it already counts as initialized. Another test's first open can still be in it, so
sqlite3_initialize()returning doesn't mean SQLCipher's handler exists yet. The module also callssqlcipher_extra_init, which is idempotent and runs under SQLite's main mutex, so it waits for that init to finish (or does it itself) before registering.How it was tested
Same binary,
sig_core-… expire -qrun 50 times in a row:sqlite3_initializeonlypresage,group,sticker× 10 each, no crash; the full suite × 3, 537 passed, no crash. The full suite's wall time equals its "finished in" (14.3 s), so the wait doesn't hold up exit.sig_core-*.ipsreports since the fix.--all-targets -D warnings) passes through the pre-commit hook.cfg(test)code.The app itself: when it quits, its connections are open and idle, not closing, so the race needs a close in progress at exit. Not seen in the app's crash reports.
Closes #120