peer: make PingManager.Stop infallible

This commit is contained in:
Keagan McClelland 2024-05-15 14:27:45 -07:00
parent 94a9baefeb
commit 61191a576d
3 changed files with 7 additions and 13 deletions

View File

@ -1257,15 +1257,13 @@ func (p *Brontide) Disconnect(reason 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.
p.cfg.Conn.Close()
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.

View File

@ -196,12 +196,10 @@ func (m *PingManager) pingHandler() {
}
}
// Stop interrupts the goroutines that the PingManager owns. Can only be called
// when the PingManager is running.
func (m *PingManager) Stop() error {
// Stop interrupts the goroutines that the PingManager owns.
func (m *PingManager) Stop() {
if m.pingTicker == nil {
return errors.New("PingManager cannot be stopped because it " +
"isn't running")
return
}
m.stopped.Do(func() {
@ -211,8 +209,6 @@ func (m *PingManager) Stop() error {
m.pingTicker.Stop()
m.pingTimeout.Stop()
})
return nil
}
// setPingState is a private method to keep track of all of the fields we need

View File

@ -83,6 +83,6 @@ func TestPingManager(t *testing.T) {
require.False(t, test.result)
}
require.NoError(t, mgr.Stop(), "Could not stop pingManager")
mgr.Stop()
}
}