-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Don't cache sqlite connections for macros #1930
Don't cache sqlite connections for macros #1930
Conversation
The |
Any pointers on where to look and how to debug the locking? I'm not familiar with the whole migrations section of the codebase |
I've spent the last Something that's annoyingly misleading:
What I thought was happening was that because we're doing What's really weird, though, is that we set a busy handler with After some more experimenting and simplifying the repro, I found that the error appears to occur in setting the initial Digging further, I think it's specifically due to the However, this is happening concurrently to other connections either having an This also explains why it would fail the first time but succeed the second, because one of the concurrent build tasks already changed the journaling mode and so no exclusive lock is necessary. So I added code in https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/sqlite/options/connect.rs#L13 to execute each However, upon learning more about journaling modes, I think there's a significant mitigation we can apply here: we should not be sending I think the WAL-by-default is a holdover from when we were experimenting with trying to make SQLite nonblocking without needing a worker thread. WAL mode is very cool and potentially very fast, but it comes with tradeoffs that the user should probably consider, and doesn't necessarily apply to every use case. It really should be the user's choice whether to enable it or not. Fortunately, it shouldn't be a breaking change to drop it as the default as any database created in WAL mode will retain the setting unless explicitly changed with |
Thanks a lot for covering all of that! It clears up a lot of questions/confusion I had. It certainly covers a lot of information that I wasn't aware of, and is a much deeper dive into the root cause analysis than I would have been able to manage 😅 I'll leave this PR open as a possible work-around, but feel free to close it once the change for |
This is still probably a decent fix for the temporary files being left around even when in WAL mode, however. I would add |
I added the explicit close, but there are still occasionally temporary files after running the repro script (in 4 runs of 20). It's worth noting that this same behavior sometimes happens back on |
If it exits early with an error then the database might not get closed properly. I might do a refactor that lets the SQLite codepath execute directly in blocking mode so the database always gets cleaned up properly since it would be owned by the main thread instead of a daemon thread. |
Fixes #1929
This works around the issue mentioned in #1929 by not including SQLite for the cached connection. I've confirmed using the repro provided in the issue that this no longer runs into the problem of the database reporting that it's busy for several seconds after being reset when journaling is turned off.
It is worth noting that I still don't really know what the root cause of the issue is...
Random other things I've noticed regarding the issue:
check
instead ofclippy
clippy
, but 1/10 withcheck
-shm
and-wal
files very rarely after running the repro script. I'm not really sure how to inspect them, so I don't know why they occasionally stick around