-
Notifications
You must be signed in to change notification settings - Fork 138
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
"unable to open database file" with Python 3.11 and PySide6 threads #295
Comments
How many threads are there? try moving the cache reference to a single global reference. Opening and closing it a gain and again in fast succession from multiple threads is likely to cause issues. |
To give more context, with python 3.10, 3.9 it works perfectly (several days). What I see with Python 3.11 is that sometimes a thread leaks a file descriptor (doesn't look systematic) so I need repeat quite a lot of requests to reach 1024 opened files. Is that possible that somehow diskcache or sqlite3 reopen the database because it lost the previous fd from within the same thread? |
I don’t think so. Sounds like a problem at a lower level than DiskCache. |
@grantjenks thanks for your help, I will continue investigating. I must be able to build a simple reproducer at some point. |
Hello, Having done some digging into this. I can state that for our case with SciQLop the file descriptor leak becomes apparent only on python3.11 as, in python3.11 SQLite added LRU caching to the connection so there are additional referrers to this connection that are not seen in python3.10, and for a reason unknown this case is always true (apart from two cases on app start) So, with the additional references, and the close function not closing, the file descriptor leak appears, or so it seems. I have validated this by essentially undoing the LRU cache on 3.11 by modifying the This is obviously not ideal, but just to prove a point.
My guess right now is some incompatibility between |
@PhilipDeegan, could you try building CPython with this patch? It should explicitly break the cycle: diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 0a6633972c..fcd8b36d41 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -410,8 +410,34 @@ clear_callback_context(callback_context *ctx)
}
static int
-connection_clear(pysqlite_Connection *self)
+cache_clear(pysqlite_Connection *self)
{
+ PyObject *cache = self->statement_cache;
+ if (cache == NULL) {
+ return 0;
+ }
+ PyObject *clear = PyObject_GetAttrString(cache, "cache_clear");
+ if (clear == NULL) {
+ PyErr_WriteUnraisable(cache);
+ return -1;
+ }
+ PyObject *ret = PyObject_CallNoArgs(clear);
+ Py_DECREF(clear);
+ if (ret == NULL) {
+ PyErr_WriteUnraisable(cache);
+ return -1;
+ }
+ Py_DECREF(ret);
+ return 0;
+}
+
+static int
+connection_clear(PyObject *obj)
+{
+ pysqlite_Connection *self = (pysqlite_Connection *)obj;
+ if (cache_clear(self) < 0) {
+ PyErr_WriteUnraisable(obj);
+ }
Py_CLEAR(self->statement_cache);
Py_CLEAR(self->cursors);
Py_CLEAR(self->blobs); Also note that the Django issue linked in the OP was solved by explicit resource management; see the discussion for details. |
I have compiled python 3.11.4 with the suggested patch and it does not appear to resolve the issue As before, the gc edits to Is there something else you might suggest? |
Not from the top of my head; I'll see if I can reproduce this on my Mac and get back to you. |
I think I solved the underlying issue by implementing a basic/naive thread storage that works with Qt/PySide6 threads: Where |
Hello,
With Python 3.11, I get "unable to open database file" quite quickly and "easily".
It turns out that my app has way too many "cache.db" opened. This looks like a leak, I tried to build a simple reproducer without any success yet.
I'm not sure how to track this down, it seems related to using diskcache from PySide 6 threads (QThread).
Could this be related to python/cpython#97641 and python/cpython#108015 ?
Do you have any idea how to investigate or better to solve this 😅?
The thread is implemented here and here in another package is the shared diskcache wrapper that seems to leak file descriptors.
The text was updated successfully, but these errors were encountered: