Merge pull request #6140 from bottlepay/fix-duplicate-close

htlcswitch: fix duplicate close
This commit is contained in:
Oliver Gugger 2022-01-11 11:08:30 +01:00 committed by GitHub
commit 617be6f994
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 20 deletions

View file

@ -67,6 +67,8 @@ connection from the watch-only node.
* [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
* [ChanStatusFlags is now
@ -82,6 +84,7 @@ connection from the watch-only node.
* Bjarne Magnussen
* Elle Mouton
* Harsha Goli
* Joost Jager
* Martin Habovštiak
* Naveen Srinivasan
* Oliver Gugger

2
go.mod
View file

@ -46,7 +46,7 @@ require (
github.com/lightningnetwork/lnd/cert v1.1.0
github.com/lightningnetwork/lnd/clock v1.1.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/ticker v1.1.0
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796

View file

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

View file

@ -31,14 +31,14 @@ func tempDecayedLogPath(t *testing.T) string {
// startup sets up the DecayedLog and possibly the garbage collector.
func startup(dbPath string, notifier bool) (sphinx.ReplayLog,
*mock.ChainNotifier, *sphinx.HashPrefix, error) {
*mock.ChainNotifier, *sphinx.HashPrefix, func(), error) {
cfg := &kvdb.BoltConfig{
DBTimeout: time.Second,
}
backend, err := NewBoltBackendCreator(dbPath, "sphinxreplay.db")(cfg)
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)
}
@ -63,7 +63,7 @@ func startup(dbPath string, notifier bool) (sphinx.ReplayLog,
// Open the channeldb (start the garbage collector)
err = log.Start()
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}
// 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
_, err = rand.Read(hashedSecret[:])
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
@ -93,7 +98,7 @@ func TestDecayedLogGarbageCollector(t *testing.T) {
dbPath := tempDecayedLogPath(t)
d, notifier, hashedSecret, err := startup(dbPath, true)
d, notifier, hashedSecret, _, err := startup(dbPath, true)
if err != nil {
t.Fatalf("Unable to start up DecayedLog: %v", err)
}
@ -154,7 +159,7 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
dbPath := tempDecayedLogPath(t)
d, _, hashedSecret, err := startup(dbPath, true)
d, _, hashedSecret, stop, err := startup(dbPath, true)
if err != nil {
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.
d.Stop()
stop()
d2, notifier2, _, err := startup(dbPath, true)
d2, notifier2, _, _, err := startup(dbPath, true)
if err != nil {
t.Fatalf("Unable to restart DecayedLog: %v", err)
}
@ -210,7 +215,7 @@ func TestDecayedLogInsertionAndDeletion(t *testing.T) {
dbPath := tempDecayedLogPath(t)
d, _, hashedSecret, err := startup(dbPath, false)
d, _, hashedSecret, _, err := startup(dbPath, false)
if err != nil {
t.Fatalf("Unable to start up DecayedLog: %v", err)
}
@ -248,7 +253,7 @@ func TestDecayedLogStartAndStop(t *testing.T) {
dbPath := tempDecayedLogPath(t)
d, _, hashedSecret, err := startup(dbPath, false)
d, _, hashedSecret, stop, err := startup(dbPath, false)
if err != nil {
t.Fatalf("Unable to start up DecayedLog: %v", err)
}
@ -261,9 +266,9 @@ func TestDecayedLogStartAndStop(t *testing.T) {
}
// Shutdown the DecayedLog's channeldb
d.Stop()
stop()
d2, _, hashedSecret2, err := startup(dbPath, false)
d2, _, hashedSecret2, stop, err := startup(dbPath, false)
if err != nil {
t.Fatalf("Unable to restart DecayedLog: %v", err)
}
@ -288,9 +293,9 @@ func TestDecayedLogStartAndStop(t *testing.T) {
}
// Shutdown the DecayedLog's channeldb
d2.Stop()
stop()
d3, _, hashedSecret3, err := startup(dbPath, false)
d3, _, hashedSecret3, _, err := startup(dbPath, false)
if err != nil {
t.Fatalf("Unable to restart DecayedLog: %v", err)
}
@ -314,7 +319,7 @@ func TestDecayedLogStorageAndRetrieval(t *testing.T) {
dbPath := tempDecayedLogPath(t)
d, _, hashedSecret, err := startup(dbPath, false)
d, _, hashedSecret, _, err := startup(dbPath, false)
if err != nil {
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.
// This function is part of the walletdb.Db interface implementation.
func (db *db) Close() error {
log.Infof("Closing database %v", db.prefix)
return dbConns.Close(db.cfg.Dsn)
}