SQLite error: database is locked
I am using HLS on a large project with VSCode, and I am being spammed with the following the error:
Error condition, please check your setup and/or the issue tracker:
HieDb writer thread SQLite error:
SQLite3 returned ErrorBusy while attempting to perform step: database is locked
I've tried restarting HLS and destroying any stack cache (didn't really expect that one to work!). Happy to provide anything else if there's not enough to go on here. I am thinking there's a manual way to clear the lock, but I don't know what that is!
You can try removing ~/.cache/ghcide.
I run into this problem too. Restarting VSCode fixes it temporarily, but I wonder if there's a better solution?
According to https://www.sqlite.org/rescode.html#locked it says if not in shared memory mode then this error only occurs if a "conflict" happens on the same connection. So because shared memory is off (I think), then it must be because of a conflict.
The only operations I see that might do this after HLS has started up is when indexing hie files (addRefsFromLoaded from hiedb), and when setSomethingModified (deleteMissingRealFiles from hiedb) which happens when closing files/workspace config changes. All writes to the hiedb are queued up, but the reads aren't, so my theory is that a read, and a delete on the same table or row is happening simultaneously resulting in a locked error.
Another possibility is writes are happening simultaneously at startup somewhere, but there are only a few places that can happen, writer thread startup, and runWithDb.
So if my theory is actually right then I guess one way of fixing it is to retry not only on SQLITE_BUSY but SQLITE_LOCKED as well.
hls-call-hierarchy-plugin had a hiedb write before hls-1.7.0.0, but I never saw errors like this while I'm debugging that, just write here for reference.
I believe this is the bug being discussed in https://github.com/haskell/vscode-haskell/issues/300 and https://github.com/haskell/vscode-haskell/issues/480
Briefly, it seems the VSCode Haskell extension sometimes starts up more than one HLS. That would explain why you get database lock errors. You will probably see duplicate info on popups driven by HLS as well.