Document/Fix race condition when using Sqlitex.Server with transactions #85
Description
As far as I see, using begin
and end
together with Sqlitex.Server
has a race condition when two processes are sending messages:
Serialized:
A -> Server: "begin"
A -> Server: "Insert into foo..."
A -> Server: "rollback"
B -> Server: "select * from foo"
Parallel:
A -> Server: "begin"
A -> Server: "Insert into ..."
B -> Server: "select * from foo"
A -> Server: "commit"
The correct result for the select * from foo
of B
would be []
, but with this race condition, B
will see the data A
inserted in a transaction which gets canceled.
To me this looks like an inherent issue with the current implementation of Sqlitex.Server
. However, we could work around this by moving it behind something more resembling a connection pool which will spawn a new instance for each process connecting to it, monitoring that process, and closing the connections when the process exits (or after some timeout).
Do you think this solution would work, or do you see any issues? If everything looks good, I might try to contribute a pool like this in the next few days.