@@ -862,12 +862,16 @@ func (s *Server) Name() msgmux.EndpointName {
862862//
863863// NOTE: This method is part of the msgmux.MsgEndpoint interface.
864864func (s * Server ) CanHandle (msg msgmux.PeerMsg ) bool {
865- err := s .waitForReady ()
866- if err != nil {
867- srvrLog .Debugf ("Can't handle PeerMsg, server not ready %v" ,
868- err )
865+ // We can't wait for ready here, as this method is potentially called
866+ // during startup. The `CanHandle` method is stateless, so we can call
867+ // it if the funding controller has been created (but potentially has
868+ // not yet been started).
869+ if s == nil || s .cfg == nil || s .cfg .AuxFundingController == nil {
870+ // This shouldn't happen, the server and funding controller
871+ // should always be initialized before the msgmux is started.
869872 return false
870873 }
874+
871875 return s .cfg .AuxFundingController .CanHandle (msg )
872876}
873877
@@ -876,12 +880,18 @@ func (s *Server) CanHandle(msg msgmux.PeerMsg) bool {
876880//
877881// NOTE: This method is part of the msgmux.MsgEndpoint interface.
878882func (s * Server ) SendMessage (ctx context.Context , msg msgmux.PeerMsg ) bool {
879- err := s .waitForReady ()
880- if err != nil {
881- srvrLog .Debugf ("Failed to send PeerMsg, server not ready %v" ,
882- err )
883+ // We can't wait for ready here, as this method is potentially called
884+ // during startup. The `SendMessage` method will buffer messages that
885+ // come in between the funding controller being created and it being
886+ // started (which only happens after waitForReady fires). So it's safe
887+ // to call it here, as long as the funding controller has been created.
888+ if s == nil || s .cfg == nil || s .cfg .AuxFundingController == nil {
889+ // This shouldn't happen, the CanHandle method is always called
890+ // first, and that should've already returned false in this
891+ // case.
883892 return false
884893 }
894+
885895 return s .cfg .AuxFundingController .SendMessage (ctx , msg )
886896}
887897
0 commit comments