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.
pull/20/head
Oliver Gugger 3 years ago
parent af356685c1
commit 994b669a0c
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -2,6 +2,7 @@ package main
import (
"fmt"
"go.etcd.io/bbolt"
"os"
"strings"
@ -140,6 +141,11 @@ func (c *walletInfoCommand) Execute(_ *cobra.Command, _ []string) error {
"bdb", lncfg.CleanAndExpandPath(c.WalletDB), false,
lnd.DefaultOpenTimeout,
)
if err == bbolt.ErrTimeout {
return fmt.Errorf("error opening wallet database, make sure " +
"lnd is not running and holding the exclusive lock " +
"on the wallet")
}
if err != nil {
return fmt.Errorf("error opening wallet database: %v", err)
}

@ -1,6 +1,7 @@
package lnd
import (
"fmt"
"io"
"os"
"time"
@ -16,6 +17,11 @@ const (
func OpenDB(dbPath string, readonly bool) (*channeldb.DB, error) {
backend, err := openDB(dbPath, false, readonly, DefaultOpenTimeout)
if err == bbolt.ErrTimeout {
return nil, fmt.Errorf("error opening %s: make sure lnd is "+
"not running, database is locked by another process",
dbPath)
}
if err != nil {
return nil, err
}

Loading…
Cancel
Save