Closed EvanHahn closed 5 months ago
I might be wrong about this, though!
You are. Quoting the SQLite docs you've linked:
- Multi-thread. In this mode, SQLite can be safely used by multiple threads provided that no single database connection nor any object derived from database connection, such as a prepared statement, is used in two or more threads at the same time.
This is exactly the case here. If you're using worker threads you open a new connection in the thread. Nothing is ever shared across thread boundaries (the structured cloning algorithm wouldn't even allow passing connections or prepared statements, because JavaScript threads are mostly foolproof).
This answers my question. Thank you!
Short version: should this library recommend changing the threading mode to "serialized" when using worker threads?
Long version:
SQLite has three threading modes: "single-thread", "multi-thread", and "serialized". Only the last one is fully safe for multi-threaded use.
This library supports worker threads, yet it is compiled with the "multi-thread" option—confusingly, not totally safe for multi-threaded use. This seems like it might lead to bugs, such as database corruption.
To me, it seems like there are several possible solutions to this problem:
SQLITE_THREADSAFE=1
).SQLITE_THREADSAFE=1
, or assume the risks.I might be wrong about this, though!
If we decide to take action on this issue, I'm happy to do the work.