Skip to content

Commit f09c517

Browse files
committed
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.
1 parent b028af1 commit f09c517

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
@@ -532,6 +532,11 @@ type Brontide struct {
532532
// off new wire messages for handing.
533533
msgRouter fn.Option[msgmux.Router]
534534

535+
// globalMsgRouter is a flag that indicates whether we have a global
536+
// msg router. If so, then we don't worry about stopping the msg router
537+
// when a peer disconnects.
538+
globalMsgRouter bool
539+
535540
startReady chan struct{}
536541
quit chan struct{}
537542
wg sync.WaitGroup
@@ -547,6 +552,11 @@ var _ lnpeer.Peer = (*Brontide)(nil)
547552
func NewBrontide(cfg Config) *Brontide {
548553
logPrefix := fmt.Sprintf("Peer(%x):", cfg.PubKeyBytes)
549554

555+
// We have a global message router if one was passed in via the config.
556+
// In this case, we don't need to attempt to tear it down when the peer
557+
// is stopped.
558+
globalMsgRouter := cfg.MsgRouter.IsSome()
559+
550560
// We'll either use the msg router instance passed in, or create a new
551561
// blank instance.
552562
msgRouter := cfg.MsgRouter.Alt(fn.Some[msgmux.Router](
@@ -576,6 +586,7 @@ func NewBrontide(cfg Config) *Brontide {
576586
quit: make(chan struct{}),
577587
log: build.NewPrefixLog(logPrefix, peerLog),
578588
msgRouter: msgRouter,
589+
globalMsgRouter: globalMsgRouter,
579590
}
580591

581592
if cfg.Conn != nil && cfg.Conn.RemoteAddr() != nil {
@@ -1393,9 +1404,13 @@ func (p *Brontide) Disconnect(reason error) {
13931404

13941405
close(p.quit)
13951406

1396-
p.msgRouter.WhenSome(func(router msgmux.Router) {
1397-
router.Stop()
1398-
})
1407+
// If our msg router isn't global (local to this instance), then we'll
1408+
// stop it. Otherwise, we'll leave it running.
1409+
if !p.globalMsgRouter {
1410+
p.msgRouter.WhenSome(func(router msgmux.Router) {
1411+
router.Stop()
1412+
})
1413+
}
13991414
}
14001415

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

0 commit comments

Comments
 (0)