From 994b669a0cec054cfb801e115b95764e3a846803 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 7 May 2021 19:17:29 +0200 Subject: [PATCH] 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. --- cmd/chantools/walletinfo.go | 6 ++++++ lnd/channeldb.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/cmd/chantools/walletinfo.go b/cmd/chantools/walletinfo.go index 16fe078..91e0a00 100644 --- a/cmd/chantools/walletinfo.go +++ b/cmd/chantools/walletinfo.go @@ -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) } diff --git a/lnd/channeldb.go b/lnd/channeldb.go index bae3e98..626c40c 100644 --- a/lnd/channeldb.go +++ b/lnd/channeldb.go @@ -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 }