#4430·sqlx

SQLCipher crashes on a segfault

Author: grahamcCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbug

I have found these related issues/pull requests

I don't see any issues mentioning any SQLCipher crashes in this repo, but did come across this related issue in the sqlcipher repo: https://github.com/sqlcipher/sqlcipher/issues/598

Description

In my testing, the sqlcipher test suite crashes about 8% of the time. I recently saw this while rebasing a PR of mine (#4343), and decided to have a robot look into it.

Here are all the failures exclusively caused by SQLCipher segfaults since 2026-07-01:

And a few more where there were additional errors, but SQLCipher also segfaulted:

It looks like this is because dropping the connection causes the worker thread to call sqlite3_close, which races SQLCipher's atexit handler which scribbles over its memory and frees its providers etc.

This problem does not replicate if the test suite calls close and then drops the connection.

I have a potential fix for this, but I did not author it by hand and I don't want to spam you. I can send it if you'd like me to.

Reproduction steps

Re-run sqlite-sqlcipher a few hundred times.

SQLx version

b54008a3 (head)

Enabled SQLx features

any, macros, migrate, sqlite, _unstable-all-types, runtime-tokio, sqlite-preupdate-hook

Database server and version

SQLite 3.50.4, SQLCipher 4.10.0

Operating system

Linux

Rust version

1.94.1, 1.98.1