mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-20 21:30:06 +02:00
peer: make PingManager.Stop infallible
This commit is contained in:
@@ -1257,15 +1257,13 @@ func (p *Brontide) Disconnect(reason error) {
|
|||||||
|
|
||||||
p.log.Infof(err.Error())
|
p.log.Infof(err.Error())
|
||||||
|
|
||||||
|
// Stop PingManager before closing TCP connection.
|
||||||
|
p.pingManager.Stop()
|
||||||
|
|
||||||
// Ensure that the TCP connection is properly closed before continuing.
|
// Ensure that the TCP connection is properly closed before continuing.
|
||||||
p.cfg.Conn.Close()
|
p.cfg.Conn.Close()
|
||||||
|
|
||||||
close(p.quit)
|
close(p.quit)
|
||||||
|
|
||||||
if err := p.pingManager.Stop(); err != nil {
|
|
||||||
p.log.Errorf("couldn't stop pingManager during disconnect: %v",
|
|
||||||
err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns the string representation of this peer.
|
// String returns the string representation of this peer.
|
||||||
|
@@ -196,12 +196,10 @@ func (m *PingManager) pingHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop interrupts the goroutines that the PingManager owns. Can only be called
|
// Stop interrupts the goroutines that the PingManager owns.
|
||||||
// when the PingManager is running.
|
func (m *PingManager) Stop() {
|
||||||
func (m *PingManager) Stop() error {
|
|
||||||
if m.pingTicker == nil {
|
if m.pingTicker == nil {
|
||||||
return errors.New("PingManager cannot be stopped because it " +
|
return
|
||||||
"isn't running")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.stopped.Do(func() {
|
m.stopped.Do(func() {
|
||||||
@@ -211,8 +209,6 @@ func (m *PingManager) Stop() error {
|
|||||||
m.pingTicker.Stop()
|
m.pingTicker.Stop()
|
||||||
m.pingTimeout.Stop()
|
m.pingTimeout.Stop()
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setPingState is a private method to keep track of all of the fields we need
|
// setPingState is a private method to keep track of all of the fields we need
|
||||||
|
@@ -83,6 +83,6 @@ func TestPingManager(t *testing.T) {
|
|||||||
require.False(t, test.result)
|
require.False(t, test.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, mgr.Stop(), "Could not stop pingManager")
|
mgr.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user