Skip to content

Commit

Permalink
Merge pull request #8904 from lightningnetwork/global-msg-router-fix
Browse files Browse the repository at this point in the history
peer: don't stop global msg router
  • Loading branch information
Roasbeef committed Jul 10, 2024
2 parents 8d83880 + 0cd11ad commit 7ffadde
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions peer/brontide.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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](
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7ffadde

Please sign in to comment.