Skip to content

Commit 7ffadde

Browse files
authored
Merge pull request #8904 from lightningnetwork/global-msg-router-fix
peer: don't stop global msg router
2 parents 8d83880 + 0cd11ad commit 7ffadde

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

peer/brontide.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ type Brontide struct {
559559
// new wire messages for handing.
560560
msgRouter fn.Option[protofsm.MsgRouter]
561561

562+
// globalMsgRouter is a flag that indicates whether we have a global
563+
// msg router. If so, then we don't worry about stopping the msg router
564+
// when a peer disconnects.
565+
globalMsgRouter bool
566+
562567
startReady chan struct{}
563568
quit chan struct{}
564569
wg sync.WaitGroup
@@ -574,6 +579,11 @@ var _ lnpeer.Peer = (*Brontide)(nil)
574579
func NewBrontide(cfg Config) *Brontide {
575580
logPrefix := fmt.Sprintf("Peer(%x):", cfg.PubKeyBytes)
576581

582+
// We have a global message router if one was passed in via the config.
583+
// In this case, we don't need to attempt to tear it down when the peer
584+
// is stopped.
585+
globalMsgRouter := cfg.MsgRouter.IsSome()
586+
577587
// We'll either use the msg router instance passed in, or create a new
578588
// blank instance.
579589
msgRouter := cfg.MsgRouter.Alt(fn.Some[protofsm.MsgRouter](
@@ -603,6 +613,7 @@ func NewBrontide(cfg Config) *Brontide {
603613
quit: make(chan struct{}),
604614
log: build.NewPrefixLog(logPrefix, peerLog),
605615
msgRouter: msgRouter,
616+
globalMsgRouter: globalMsgRouter,
606617
}
607618

608619
if cfg.Conn != nil && cfg.Conn.RemoteAddr() != nil {
@@ -1397,9 +1408,13 @@ func (p *Brontide) Disconnect(reason error) {
13971408

13981409
close(p.quit)
13991410

1400-
p.msgRouter.WhenSome(func(router protofsm.MsgRouter) {
1401-
router.Stop()
1402-
})
1411+
// If our msg router isn't global (local to this instance), then we'll
1412+
// stop it. Otherwise, we'll leave it running.
1413+
if !p.globalMsgRouter {
1414+
p.msgRouter.WhenSome(func(router protofsm.MsgRouter) {
1415+
router.Stop()
1416+
})
1417+
}
14031418
}
14041419

14051420
// String returns the string representation of this peer.

0 commit comments

Comments
 (0)