mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
peer: don't stop global msg router
In this commit, we fix a bug that would cause a global message router to be stopped anytime a peer disconnected. The global msg router only allows `Start` to be called once, so afterwards, no messages would properly be routed.
This commit is contained in:
parent
8d83880161
commit
0cd11ad847
@ -559,6 +559,11 @@ type Brontide struct {
|
||||
// new wire messages for handing.
|
||||
msgRouter fn.Option[protofsm.MsgRouter]
|
||||
|
||||
// globalMsgRouter is a flag that indicates whether we have a global
|
||||
// msg router. If so, then we don't worry about stopping the msg router
|
||||
// when a peer disconnects.
|
||||
globalMsgRouter bool
|
||||
|
||||
startReady chan struct{}
|
||||
quit chan struct{}
|
||||
wg sync.WaitGroup
|
||||
@ -574,6 +579,11 @@ var _ lnpeer.Peer = (*Brontide)(nil)
|
||||
func NewBrontide(cfg Config) *Brontide {
|
||||
logPrefix := fmt.Sprintf("Peer(%x):", cfg.PubKeyBytes)
|
||||
|
||||
// We have a global message router if one was passed in via the config.
|
||||
// In this case, we don't need to attempt to tear it down when the peer
|
||||
// is stopped.
|
||||
globalMsgRouter := cfg.MsgRouter.IsSome()
|
||||
|
||||
// We'll either use the msg router instance passed in, or create a new
|
||||
// blank instance.
|
||||
msgRouter := cfg.MsgRouter.Alt(fn.Some[protofsm.MsgRouter](
|
||||
@ -603,6 +613,7 @@ func NewBrontide(cfg Config) *Brontide {
|
||||
quit: make(chan struct{}),
|
||||
log: build.NewPrefixLog(logPrefix, peerLog),
|
||||
msgRouter: msgRouter,
|
||||
globalMsgRouter: globalMsgRouter,
|
||||
}
|
||||
|
||||
if cfg.Conn != nil && cfg.Conn.RemoteAddr() != nil {
|
||||
@ -1397,9 +1408,13 @@ func (p *Brontide) Disconnect(reason error) {
|
||||
|
||||
close(p.quit)
|
||||
|
||||
p.msgRouter.WhenSome(func(router protofsm.MsgRouter) {
|
||||
router.Stop()
|
||||
})
|
||||
// If our msg router isn't global (local to this instance), then we'll
|
||||
// stop it. Otherwise, we'll leave it running.
|
||||
if !p.globalMsgRouter {
|
||||
p.msgRouter.WhenSome(func(router protofsm.MsgRouter) {
|
||||
router.Stop()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// String returns the string representation of this peer.
|
||||
|
Loading…
Reference in New Issue
Block a user