Skip to content

Commit 994b669

Browse files
committed
lnd+walletinfo: return more verbose error on DB timeout
Fixes #18. Any bbolt database has a unique lock, meaning it cannot be opened by two processes at the same time. The simple "timeout" error that is returned if opening fails is not very informative though.
1 parent af35668 commit 994b669

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cmd/chantools/walletinfo.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"go.etcd.io/bbolt"
56
"os"
67
"strings"
78

@@ -140,6 +141,11 @@ func (c *walletInfoCommand) Execute(_ *cobra.Command, _ []string) error {
140141
"bdb", lncfg.CleanAndExpandPath(c.WalletDB), false,
141142
lnd.DefaultOpenTimeout,
142143
)
144+
if err == bbolt.ErrTimeout {
145+
return fmt.Errorf("error opening wallet database, make sure " +
146+
"lnd is not running and holding the exclusive lock " +
147+
"on the wallet")
148+
}
143149
if err != nil {
144150
return fmt.Errorf("error opening wallet database: %v", err)
145151
}

lnd/channeldb.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lnd
22

33
import (
4+
"fmt"
45
"io"
56
"os"
67
"time"
@@ -16,6 +17,11 @@ const (
1617

1718
func OpenDB(dbPath string, readonly bool) (*channeldb.DB, error) {
1819
backend, err := openDB(dbPath, false, readonly, DefaultOpenTimeout)
20+
if err == bbolt.ErrTimeout {
21+
return nil, fmt.Errorf("error opening %s: make sure lnd is "+
22+
"not running, database is locked by another process",
23+
dbPath)
24+
}
1925
if err != nil {
2026
return nil, err
2127
}

0 commit comments

Comments
 (0)