haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

SQLite error: database is locked

Open JoeMShanahan opened this issue 3 years ago • 6 comments

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!

JoeMShanahan avatar May 26 '22 09:05 JoeMShanahan

You can try removing ~/.cache/ghcide.

eddiemundo avatar May 27 '22 02:05 eddiemundo

I run into this problem too. Restarting VSCode fixes it temporarily, but I wonder if there's a better solution?

aryairani avatar May 27 '22 20:05 aryairani

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.

eddiemundo avatar May 29 '22 06:05 eddiemundo

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.

July541 avatar May 29 '22 07:05 July541

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.

PaulJohnson avatar Dec 22 '22 15:12 PaulJohnson