tursodatabase/libsql

Thread safety assertion woes

Opened this issue · 1 comments

We had a pull request to relax the thread safety checks in #1887. However we ended up opting for for #1891, but it requires clients to rely on something we tag as unsafe. Let's look into fixing thread safety checks in a safe way.

The issue manifests, for example, with some Tauri apps:

Failed to initialize embedded replica: ❌ spawn_blocking task failed: task 48 panicked with message "assertion `left == right` failed: libsql was configured with an incorrect threading configuration and\n                    the api is not safe to use. Please check that no multi-thread options have\n                    been set. If nothing was configured then please open an issue at:\n                    https://github.com/libsql/libsql\n  left: 21\n right: 0"

Full Discord thread here: https://discord.com/channels/933071162680958986/1379937960547586098

@penberg My understanding is applying SQLITE_OPEN_FULLMUTEX when opening a connection is what makes #1887 safe. In #1891 you've allowed to bypass the thread-safety check, but we don't have any option to set SQLITE_OPEN_FULLMUTEX using the public API. Am I misreading something here? Would you be ok with changing libsql API to enforce SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_NOMUTEX according to user's needs?