-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-threaded access to encrypted database #73
Comments
Yes, that should be sufficient. In SQLite3MC each database connection operates on its own copy of the cipher configuration table, and write access to this data structure is protected by mutexes.
Can you somehow track down in more detail, when and where these access violations occur? Does it happen on opening a database or on configuring the cipher scheme or on regular page read/write operations or on closing a connection?
Of course, it is possible that I overlooked places in the code, where using a mutex would be necessary, although I tried my best to use mutexes, whenever changes to cipher parameters are done. Access violations usually indicate that a pointer is null, was not initialized properly, or points to something already freed. I certainly will try to find out whether such places exist in the code, but it would be really helpful to have more information about the circumstances, when access violations happen. |
I will try to reproduce the issue again, but up to now, I already had two callstacks: |
This one is executing a VACUUM statement:
|
This one is just opening a connection (which might have come from the connection pool):
|
Thank you very much for the callstacks. This helps a lot. Obviously, accessing a global VFS structure doesn't work as expected, although the access is guarded by a mutex. I will try to analyze what's going on and to find a solution. |
Attempt to solve issue #73: global VFS management structure did not work properly in multi-threaded environment.
I modified the handling of the internal VFS management, so that the global structure is no longer used. I hope that solves the issue. Please give it a try. TIA. |
Due to life intervening in unexpected ways I won't be able to test it the enxt few days, but I will definitely post results here ASAP. |
TIA. I'll wait for your feedback (hopefully confirming that the issue is solved), before making a new release. |
I tested and it seems commit 9fd21f4 fixes the issue as expected. Thanks for reactig quickly!! |
Thanks for testing and confirming. I'm going to close the issue. Please reopen if necessary. |
One follow-up question regarding severity of this bug: is there any chance of corrupting databases or changing data in the wrong db in a multi-threaded scenario (one thread per db) due to this bug? |
AFAICT it is extremely unlikely that the bug can cause database corruption. The global VFS management structure (used in versions prior to 1.4.0) is accessed only on opening or closing a database file, that is, before or after any real I/O takes place. The database file I/O itself is not affected. However, if the application crashes due to a null pointer access while a database file write access is underway in another thread, there is a very small residual risk for database corruption. |
Is there anything to be regarded when using sqlite3mc in a multi-threaded context where each thread accesses a single database using its own connection? I assumed that compiling with SQLITE_THREADSAFE=1 should be sufficient but in reality I get random access violations in a situation where multiple threads open their database simultaneously (I also tested with SQLITE_THREADSAFE=2 which made no difference).
To rule out sqlite3mc-specific code I tested the identical situation with the same databases but removed encryption beforehand.
The access violations are then gone, so it seems there might indeed be some code in encryption, cipher/key setup which is not thread-safe?
The text was updated successfully, but these errors were encountered: