@@ -119,6 +119,8 @@ func (cs *commandService) CreateConnection(
119119// If any connection or unrecoverable errors occur, return and agent should re-establish a subscription.
120120// If errors occur with applying the config, log and put those errors into the status queue to be written
121121// to the Gateway status.
122+ //
123+ //nolint:gocyclo // could be room for improvement here
122124func (cs * commandService ) Subscribe (in pb.CommandService_SubscribeServer ) error {
123125 ctx := in .Context ()
124126
@@ -179,6 +181,7 @@ func (cs *commandService) Subscribe(in pb.CommandService_SubscribeServer) error
179181 panic (fmt .Sprintf ("unknown request type %d" , msg .Type ))
180182 }
181183
184+ cs .logger .V (1 ).Info ("Sending configuration to agent" , "requestType" , msg .Type )
182185 if err := msgr .Send (ctx , req ); err != nil {
183186 cs .logger .Error (err , "error sending request to agent" )
184187 deployment .SetPodErrorStatus (conn .PodName , err )
@@ -189,7 +192,10 @@ func (cs *commandService) Subscribe(in pb.CommandService_SubscribeServer) error
189192 case err = <- msgr .Errors ():
190193 cs .logger .Error (err , "connection error" , "pod" , conn .PodName )
191194 deployment .SetPodErrorStatus (conn .PodName , err )
192- channels .ResponseCh <- struct {}{}
195+ select {
196+ case channels .ResponseCh <- struct {}{}:
197+ default :
198+ }
193199
194200 if errors .Is (err , io .EOF ) {
195201 return grpcStatus .Error (codes .Aborted , err .Error ())
@@ -198,7 +204,11 @@ func (cs *commandService) Subscribe(in pb.CommandService_SubscribeServer) error
198204 case msg := <- msgr .Messages ():
199205 res := msg .GetCommandResponse ()
200206 if res .GetStatus () != pb .CommandResponse_COMMAND_STATUS_OK {
201- err := fmt .Errorf ("bad response from agent: msg: %s; error: %s" , res .GetMessage (), res .GetError ())
207+ if isRollbackMessage (res .GetMessage ()) {
208+ // we don't care about these messages, so ignore them
209+ continue
210+ }
211+ err := fmt .Errorf ("msg: %s; error: %s" , res .GetMessage (), res .GetError ())
202212 deployment .SetPodErrorStatus (conn .PodName , err )
203213 } else {
204214 deployment .SetPodErrorStatus (conn .PodName , nil )
@@ -268,6 +278,8 @@ func (cs *commandService) setInitialConfig(
268278 for _ , action := range deployment .GetNGINXPlusActions () {
269279 // retry the API update request because sometimes nginx isn't quite ready after the config apply reload
270280 timeoutCtx , cancel := context .WithTimeout (ctx , 5 * time .Second )
281+ var overallUpstreamApplyErr error
282+
271283 if err := wait .PollUntilContextCancel (
272284 timeoutCtx ,
273285 500 * time .Millisecond ,
@@ -287,13 +299,14 @@ func (cs *commandService) setInitialConfig(
287299 }
288300
289301 if upstreamApplyErr != nil {
290- return false , nil //nolint:nilerr // this error is collected at the end
302+ overallUpstreamApplyErr = errors .Join (overallUpstreamApplyErr , upstreamApplyErr )
303+ return false , nil
291304 }
292305 return true , nil
293306 },
294307 ); err != nil {
295- if strings . Contains ( err . Error (), "bad response from agent" ) {
296- errs = append (errs , err )
308+ if overallUpstreamApplyErr != nil {
309+ errs = append (errs , overallUpstreamApplyErr )
297310 } else {
298311 cancel ()
299312 return err
@@ -330,7 +343,7 @@ func (cs *commandService) waitForInitialConfigApply(
330343 case msg := <- msgr .Messages ():
331344 res := msg .GetCommandResponse ()
332345 if res .GetStatus () != pb .CommandResponse_COMMAND_STATUS_OK {
333- applyErr := fmt .Errorf ("bad response from agent: msg: %s; error: %s" , res .GetMessage (), res .GetError ())
346+ applyErr := fmt .Errorf ("msg: %s; error: %s" , res .GetMessage (), res .GetError ())
334347 return applyErr , nil
335348 }
336349
@@ -379,6 +392,12 @@ func buildRequest(fileOverviews []*pb.File, instanceID, version string) *pb.Mana
379392 }
380393}
381394
395+ func isRollbackMessage (msg string ) bool {
396+ msgToLower := strings .ToLower (msg )
397+ return strings .Contains (msgToLower , "rollback successful" ) ||
398+ strings .Contains (msgToLower , "rollback failed" )
399+ }
400+
382401func buildPlusAPIRequest (action * pb.NGINXPlusAction , instanceID string ) * pb.ManagementPlaneRequest {
383402 return & pb.ManagementPlaneRequest {
384403 MessageMeta : & pb.MessageMeta {
0 commit comments