haskell / haskell/HieDb

`database is locked` error when hiedb is run concurrently

Open
#63 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
69
Forks
30
PR merge metrics
No merged PRs in 30d

Description

When I run `hiedb index .hiefiles` concurrently, the second process errors because the first has already locked the database:

```
$ hiedb index .hiefiles >/dev/null 2>&1 &; hiedb index .hiefiles
hiedb: SQLite3 returned ErrorBusy while attempting to perform step: database is locked
```

## Context

We're using [`ghciwatch`](https://github.com/MercuryTechnologies/ghciwatch/) for development in combination with [`static-ls`](https://github.com/josephsumabat/static-ls) for language intelligence. `ghciwatch` handles loading and compiling modules in `ghci` for rapid reloads, and `static-ls` leverages `hiedb` to provide language intelligence. (Our project is too big for `haskell-language-server`.)

We're using `ghciwatch`'s lifecycle hooks to reindex the hiefiles on reloads:

```sh
ghciwatch \
--after-reload-shell "async:hiedb -D .hiedb index .hiefiles" \
--before-restart-shell "async:hiedb -D .hiedb index .hiefiles"
```

Because `ghciwatch` runs these commands asynchronously (so that it can keep reloading and responding to changes while the files are indexed), it's possible for multiple `hiedb` processes to run at once (especially on the first load when 7500+ modules are being indexed), which has been triggering this bug.

I have a few ideas for working around this in `ghciwatch` (only allowing one of each hook to run at once, killing old hook processes before launching new ones, etc.), but I think we should fix this in `hiedb` as well.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.