Skip to content

Commit

Permalink
bolt: alert for possible lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Mar 4, 2024
1 parent 4d59383 commit 7798055
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion bolt/lib.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package bolt

import (
"fmt"
"sync/atomic"
"time"

"github.com/boltdb/bolt"
"github.com/fiatjaf/eventstore"
Expand Down Expand Up @@ -42,7 +44,18 @@ func (b *BoltBackend) Init() error {
}

// open boltdb
db, err := bolt.Open(b.Path, 0644, nil)
var db *bolt.DB
var err error
done := make(chan struct{})
go func() {
db, err = bolt.Open(b.Path, 0644, nil)
done <- struct{}{}
}()
select {
case <-done:
case <-time.After(20 * time.Second):
return fmt.Errorf("taking too long to open the bolt database at '%s', please make sure that database is not being used elsewhere because there may be a lock in place there", b.Path)
}
if err != nil {
return err
}
Expand Down

0 comments on commit 7798055

Please sign in to comment.