-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
SQLite3 multithreading cache inconsistency #118172
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
Comments
Thanks Donghee! (BTW, I'm already subscribed to the topic-sqlite3 label, so no need to ping me manually 🙂) |
is this correct use of the api though, setting LK = threading.Lock()
def execute_query():
cursor = KB.cursor()
with LK:
cursor.execute("SELECT * FROM test_table")
result = cursor.fetchall()
assert result == [(1, 'test1'), (2, 'test2'), (3, 'test3')], str(result)
return result |
I am not sure. But based on the description from the document, for serialized threading mode, "Threads may share the module, connections and cursors", and no lock needed for the old version (3.11 and older), I assume lock is not necessary. |
I can confirm that the issue appears in Python 3.12 and Python 3.13, but not in earlier versions (I tested back to Python 3.8). I also tried to revert the sqlite3 extension code back to its 3.11 state (making only a few needed C API changes), just to make sure the issue exists in the sqlite3 extension and not in the runtime. I can confirm the issue is in the sqlite3 extension. I'll do a bisect as soon as possible. |
I bisected this back to f5c85aa, which seems plausible. I'll also try to come up with a smaller repro so we can add a regression test for this. |
With python 3.12 and 3.13 fetch results from SQLite3 in multi-threading applications are not consistent. This causes an InterfaceError with bad parameter or other API misuse. Current solution is to set the cache_statement to 0. See python/cpython#118172
With python 3.12 and 3.13 fetch results from SQLite3 in multi-threading applications are not consistent. This causes an InterfaceError with bad parameter or other API misuse. Current solution is to set the cached_statement to 0. See python/cpython#118172
With python 3.12 and 3.13 fetch results from SQLite3 in multi-threading applications are not consistent. This causes an InterfaceError with bad parameter or other API misuse. Current solution is to set the cached_statement to 0. See python/cpython#118172
With python 3.12 and 3.13 fetch results from SQLite3 in multi-threading applications are not consistent. This causes an InterfaceError with bad parameter or other API misuse. Current solution is to set the cached_statement to 0. See python/cpython#118172
With python 3.12 and 3.13 fetch results from SQLite3 in multi-threading applications are not consistent. This causes an InterfaceError with bad parameter or other API misuse. Current solution is to set the cached_statement to 0. See python/cpython#118172
With python 3.12 and 3.13 fetch results from SQLite3 in multi-threading applications are not consistent. This causes an InterfaceError with bad parameter or other API misuse. Current solution is to set the cached_statement to 0. See python/cpython#118172
With python 3.12 and 3.13 fetch results from SQLite3 in multi-threading applications are not consistent. This causes an InterfaceError with bad parameter or other API misuse. Current solution is to set the cached_statement to 0. See python/cpython#118172
With python 3.12 and 3.13 fetch results from SQLite3 in multi-threading applications are not consistent. This causes an InterfaceError with bad parameter or other API misuse. Current solution is to set the cached_statement to 0. See python/cpython#118172
We also experienced this issue on Python 3.12, and worked around it by setting In our case, this issue mainly manifested itself with the following exception when running
More rarely we got some of the following exceptions when calling
We also got some errors when calling
We also got various errors when retrieving data from the
|
### Purpose: Newer versions of python return incorrect sqlite results if cached_statements is nonzero. See: python/cpython#118172 ### Current Behavior: cached_statements is set to default ### New Behavior: cached_statements is set to 0. Chia rarely repeats the same sqlite queries so hopefully this does not affect performance. ### Testing Notes: None
the op included explicitly using the same connection object from multiple threads simultaneously with |
* Update oslo.db from branch 'master' to bea56237b5cfaf3341d938210b005c99d71c50fb - Disable cached-statements on sqlite3 Since python 3.12, sqlite3 and multi threading may not work correctly. One of the current workaround is to disable cached statements. See also: python/cpython#118172 Change-Id: I35a2568474d99491b99009a8d475135d16939e2b Signed-off-by: Arnaud M <arnaud.morin@gmail.com>
Since python 3.12, sqlite3 and multi threading may not work correctly. One of the current workaround is to disable cached statements. See also: python/cpython#118172 Change-Id: I35a2568474d99491b99009a8d475135d16939e2b Signed-off-by: Arnaud M <arnaud.morin@gmail.com>
Picking this up after some time away from CPython development. I tried bisecting using a more aggressive script and managed to reproduce failures all the way back to v3.10.0a2 (!). I'm unable to reproduce with official 3.10 binaries, though, so maybe we need a more focused repro. I'll try to devote more time to this before the ultimate 3.11 bugfix release later this month. |
Bug report
Bug description:
When using SQLite3 in multi-threading application, the fetch reuslts are not consistent. After some testing, this seems to be caused by the caching.
The SQLite threading mode is serialized.
This issue only exists in python 3.12 and 3.13. No issue in 3.11.
Currently solution is to set
cached_statements=0
when connect to the database.A simple demo to reproduce the error:
Test output: (Different in each run because of inconsistent fetch results)
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: