@@ -837,12 +837,16 @@ func (s *Server) Name() msgmux.EndpointName {
837837//
838838// NOTE: This method is part of the msgmux.MsgEndpoint interface.
839839func (s * Server ) CanHandle (msg msgmux.PeerMsg ) bool {
840- err := s .waitForReady ()
841- if err != nil {
842- srvrLog .Debugf ("Can't handle PeerMsg, server not ready %v" ,
843- err )
840+ // We can't wait for ready here, as this method is potentially called
841+ // during startup. The `CanHandle` method is stateless, so we can call
842+ // it if the funding controller has been created (but potentially has
843+ // not yet been started).
844+ if s == nil || s .cfg == nil || s .cfg .AuxFundingController == nil {
845+ // This shouldn't happen, the server and funding controller
846+ // should always be initialized before the msgmux is started.
844847 return false
845848 }
849+
846850 return s .cfg .AuxFundingController .CanHandle (msg )
847851}
848852
@@ -851,12 +855,18 @@ func (s *Server) CanHandle(msg msgmux.PeerMsg) bool {
851855//
852856// NOTE: This method is part of the msgmux.MsgEndpoint interface.
853857func (s * Server ) SendMessage (ctx context.Context , msg msgmux.PeerMsg ) bool {
854- err := s .waitForReady ()
855- if err != nil {
856- srvrLog .Debugf ("Failed to send PeerMsg, server not ready %v" ,
857- err )
858+ // We can't wait for ready here, as this method is potentially called
859+ // during startup. The `SendMessage` method will buffer messages that
860+ // come in between the funding controller being created and it being
861+ // started (which only happens after waitForReady fires). So it's safe
862+ // to call it here, as long as the funding controller has been created.
863+ if s == nil || s .cfg == nil || s .cfg .AuxFundingController == nil {
864+ // This shouldn't happen, the CanHandle method is always called
865+ // first, and that should've already returned false in this
866+ // case.
858867 return false
859868 }
869+
860870 return s .cfg .AuxFundingController .SendMessage (ctx , msg )
861871}
862872
0 commit comments