diff --git a/rpcserver.go b/rpcserver.go index fd6743407..603856379 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -9251,7 +9251,7 @@ func (r *rpcServer) RegisterRPCMiddleware( } // SendCustomMessage sends a custom peer message. -func (r *rpcServer) SendCustomMessage(_ context.Context, +func (r *rpcServer) SendCustomMessage(ctx context.Context, req *lnrpc.SendCustomMessageRequest) (*lnrpc.SendCustomMessageResponse, error) { @@ -9261,7 +9261,7 @@ func (r *rpcServer) SendCustomMessage(_ context.Context, } err = r.server.SendCustomMessage( - peer, lnwire.MessageType(req.Type), req.Data, + ctx, peer, lnwire.MessageType(req.Type), req.Data, ) switch { case errors.Is(err, ErrPeerNotConnected): diff --git a/server.go b/server.go index b7d4f2370..6149db0ec 100644 --- a/server.go +++ b/server.go @@ -5263,21 +5263,24 @@ func (s *server) applyChannelUpdate(update *lnwire.ChannelUpdate1, // SendCustomMessage sends a custom message to the peer with the specified // pubkey. -func (s *server) SendCustomMessage(peerPub [33]byte, msgType lnwire.MessageType, - data []byte) error { +func (s *server) SendCustomMessage(ctx context.Context, peerPub [33]byte, + msgType lnwire.MessageType, data []byte) error { peer, err := s.FindPeerByPubStr(string(peerPub[:])) if err != nil { return err } - // We'll wait until the peer is active. + // We'll wait until the peer is active, but also listen for + // cancellation. select { case <-peer.ActiveSignal(): case <-peer.QuitSignal(): return fmt.Errorf("peer %x disconnected", peerPub) case <-s.quit: return ErrServerShuttingDown + case <-ctx.Done(): + return ctx.Err() } msg, err := lnwire.NewCustom(msgType, data)