htlcswitch: fix duplicate close

The decayed log database opening and closing is managed at a higher
level in config_builder.go.
This commit is contained in:
Joost Jager 2022-01-06 13:23:41 +01:00
parent 61bffa70f9
commit 7cd7cef6c6
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
5 changed files with 27 additions and 20 deletions

View File

@ -53,6 +53,8 @@
* [Fix Postgres itests max connections](https://github.com/lightningnetwork/lnd/pull/6116) * [Fix Postgres itests max connections](https://github.com/lightningnetwork/lnd/pull/6116)
* [Fix duplicate db connection close](https://github.com/lightningnetwork/lnd/pull/6140)
## RPC Server ## RPC Server
* [ChanStatusFlags is now * [ChanStatusFlags is now
@ -68,6 +70,7 @@
* Bjarne Magnussen * Bjarne Magnussen
* Elle Mouton * Elle Mouton
* Harsha Goli * Harsha Goli
* Joost Jager
* Martin Habovštiak * Martin Habovštiak
* Naveen Srinivasan * Naveen Srinivasan
* Oliver Gugger * Oliver Gugger

2
go.mod
View File

@ -46,7 +46,7 @@ require (
github.com/lightningnetwork/lnd/cert v1.1.0 github.com/lightningnetwork/lnd/cert v1.1.0
github.com/lightningnetwork/lnd/clock v1.1.0 github.com/lightningnetwork/lnd/clock v1.1.0
github.com/lightningnetwork/lnd/healthcheck v1.2.0 github.com/lightningnetwork/lnd/healthcheck v1.2.0
github.com/lightningnetwork/lnd/kvdb v1.2.4 github.com/lightningnetwork/lnd/kvdb v1.2.5
github.com/lightningnetwork/lnd/queue v1.1.0 github.com/lightningnetwork/lnd/queue v1.1.0
github.com/lightningnetwork/lnd/ticker v1.1.0 github.com/lightningnetwork/lnd/ticker v1.1.0
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796

View File

@ -158,9 +158,6 @@ func (d *DecayedLog) Stop() error {
d.wg.Wait() d.wg.Wait()
// Close boltdb.
d.db.Close()
return nil return nil
} }

View File

@ -31,14 +31,14 @@ func tempDecayedLogPath(t *testing.T) string {
// startup sets up the DecayedLog and possibly the garbage collector. // startup sets up the DecayedLog and possibly the garbage collector.
func startup(dbPath string, notifier bool) (sphinx.ReplayLog, func startup(dbPath string, notifier bool) (sphinx.ReplayLog,
*mock.ChainNotifier, *sphinx.HashPrefix, error) { *mock.ChainNotifier, *sphinx.HashPrefix, func(), error) {
cfg := &kvdb.BoltConfig{ cfg := &kvdb.BoltConfig{
DBTimeout: time.Second, DBTimeout: time.Second,
} }
backend, err := NewBoltBackendCreator(dbPath, "sphinxreplay.db")(cfg) backend, err := NewBoltBackendCreator(dbPath, "sphinxreplay.db")(cfg)
if err != nil { if err != nil {
return nil, nil, nil, fmt.Errorf("unable to create temporary "+ return nil, nil, nil, nil, fmt.Errorf("unable to create temporary "+
"decayed log db: %v", err) "decayed log db: %v", err)
} }
@ -63,7 +63,7 @@ func startup(dbPath string, notifier bool) (sphinx.ReplayLog,
// Open the channeldb (start the garbage collector) // Open the channeldb (start the garbage collector)
err = log.Start() err = log.Start()
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, nil, err
} }
// Create a HashPrefix identifier for a packet. Instead of actually // Create a HashPrefix identifier for a packet. Instead of actually
@ -72,10 +72,15 @@ func startup(dbPath string, notifier bool) (sphinx.ReplayLog,
var hashedSecret sphinx.HashPrefix var hashedSecret sphinx.HashPrefix
_, err = rand.Read(hashedSecret[:]) _, err = rand.Read(hashedSecret[:])
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, nil, err
} }
return log, chainNotifier, &hashedSecret, nil stop := func() {
_ = log.Stop()
backend.Close()
}
return log, chainNotifier, &hashedSecret, stop, nil
} }
// shutdown deletes the temporary directory that the test database uses // shutdown deletes the temporary directory that the test database uses
@ -93,7 +98,7 @@ func TestDecayedLogGarbageCollector(t *testing.T) {
dbPath := tempDecayedLogPath(t) dbPath := tempDecayedLogPath(t)
d, notifier, hashedSecret, err := startup(dbPath, true) d, notifier, hashedSecret, _, err := startup(dbPath, true)
if err != nil { if err != nil {
t.Fatalf("Unable to start up DecayedLog: %v", err) t.Fatalf("Unable to start up DecayedLog: %v", err)
} }
@ -154,7 +159,7 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
dbPath := tempDecayedLogPath(t) dbPath := tempDecayedLogPath(t)
d, _, hashedSecret, err := startup(dbPath, true) d, _, hashedSecret, stop, err := startup(dbPath, true)
if err != nil { if err != nil {
t.Fatalf("Unable to start up DecayedLog: %v", err) t.Fatalf("Unable to start up DecayedLog: %v", err)
} }
@ -172,9 +177,9 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
} }
// Shut down DecayedLog and the garbage collector along with it. // Shut down DecayedLog and the garbage collector along with it.
d.Stop() stop()
d2, notifier2, _, err := startup(dbPath, true) d2, notifier2, _, _, err := startup(dbPath, true)
if err != nil { if err != nil {
t.Fatalf("Unable to restart DecayedLog: %v", err) t.Fatalf("Unable to restart DecayedLog: %v", err)
} }
@ -210,7 +215,7 @@ func TestDecayedLogInsertionAndDeletion(t *testing.T) {
dbPath := tempDecayedLogPath(t) dbPath := tempDecayedLogPath(t)
d, _, hashedSecret, err := startup(dbPath, false) d, _, hashedSecret, _, err := startup(dbPath, false)
if err != nil { if err != nil {
t.Fatalf("Unable to start up DecayedLog: %v", err) t.Fatalf("Unable to start up DecayedLog: %v", err)
} }
@ -248,7 +253,7 @@ func TestDecayedLogStartAndStop(t *testing.T) {
dbPath := tempDecayedLogPath(t) dbPath := tempDecayedLogPath(t)
d, _, hashedSecret, err := startup(dbPath, false) d, _, hashedSecret, stop, err := startup(dbPath, false)
if err != nil { if err != nil {
t.Fatalf("Unable to start up DecayedLog: %v", err) t.Fatalf("Unable to start up DecayedLog: %v", err)
} }
@ -261,9 +266,9 @@ func TestDecayedLogStartAndStop(t *testing.T) {
} }
// Shutdown the DecayedLog's channeldb // Shutdown the DecayedLog's channeldb
d.Stop() stop()
d2, _, hashedSecret2, err := startup(dbPath, false) d2, _, hashedSecret2, stop, err := startup(dbPath, false)
if err != nil { if err != nil {
t.Fatalf("Unable to restart DecayedLog: %v", err) t.Fatalf("Unable to restart DecayedLog: %v", err)
} }
@ -288,9 +293,9 @@ func TestDecayedLogStartAndStop(t *testing.T) {
} }
// Shutdown the DecayedLog's channeldb // Shutdown the DecayedLog's channeldb
d2.Stop() stop()
d3, _, hashedSecret3, err := startup(dbPath, false) d3, _, hashedSecret3, _, err := startup(dbPath, false)
if err != nil { if err != nil {
t.Fatalf("Unable to restart DecayedLog: %v", err) t.Fatalf("Unable to restart DecayedLog: %v", err)
} }
@ -314,7 +319,7 @@ func TestDecayedLogStorageAndRetrieval(t *testing.T) {
dbPath := tempDecayedLogPath(t) dbPath := tempDecayedLogPath(t)
d, _, hashedSecret, err := startup(dbPath, false) d, _, hashedSecret, _, err := startup(dbPath, false)
if err != nil { if err != nil {
t.Fatalf("Unable to start up DecayedLog: %v", err) t.Fatalf("Unable to start up DecayedLog: %v", err)
} }

View File

@ -256,5 +256,7 @@ func (db *db) Copy(w io.Writer) error {
// Close cleanly shuts down the database and syncs all data. // Close cleanly shuts down the database and syncs all data.
// This function is part of the walletdb.Db interface implementation. // This function is part of the walletdb.Db interface implementation.
func (db *db) Close() error { func (db *db) Close() error {
log.Infof("Closing database %v", db.prefix)
return dbConns.Close(db.cfg.Dsn) return dbConns.Close(db.cfg.Dsn)
} }