@@ -271,7 +271,7 @@ func (s *server) ListenAndServe(ctx context.Context) <-chan []error {
271271 return errs
272272 }
273273
274- shutdownSrvs := func (errs []error ) {
274+ shutdownSrvs := func (errs []error ) [] error {
275275 if s .hcRunning {
276276 glg .Info ("authorization proxy health check server will shutdown..." )
277277 errs = appendErr (errs , s .hcShutdown (context .Background ()))
@@ -286,65 +286,50 @@ func (s *server) ListenAndServe(ctx context.Context) <-chan []error {
286286 }
287287 if s .dRunning {
288288 glg .Info ("authorization proxy debug server will shutdown..." )
289- appendErr (errs , s .dShutdown (context .Background ()))
289+ errs = appendErr (errs , s .dShutdown (context .Background ()))
290290 }
291- glg .Info ("authorization proxy has already shutdown gracefully" )
291+ if len (errs ) == 0 {
292+ glg .Info ("authorization proxy has already shutdown gracefully" )
293+ }
294+ return errs
292295 }
293296
294297 errs := make ([]error , 0 , 3 )
298+
299+ handleErr := func (err error ) {
300+ if err != nil {
301+ errs = append (errs , errors .Wrap (err , "close running servers and return any error" ))
302+ }
303+ s .mu .RLock ()
304+ errs = shutdownSrvs (errs )
305+ s .mu .RUnlock ()
306+ echan <- errs
307+ }
308+
295309 for {
296310 select {
297311 case <- ctx .Done (): // when context receive done signal, close running servers and return any error
298312 s .mu .RLock ()
299- shutdownSrvs (errs )
313+ errs = shutdownSrvs (errs )
300314 s .mu .RUnlock ()
301315 echan <- appendErr (errs , ctx .Err ())
302316 return
303317
304318 case err := <- sech : // when authorization proxy server returns, close running servers and return any error
305- if err != nil {
306- errs = append (errs , errors .Wrap (err , "close running servers and return any error" ))
307- }
308-
309- s .mu .RLock ()
310- shutdownSrvs (errs )
311- s .mu .RUnlock ()
312- echan <- errs
319+ handleErr (err )
313320 return
314321
315322 case err := <- gsech : // when authorization proxy grpc server returns, close running servers and return any error
316- if err != nil {
317- errs = append (errs , errors .Wrap (err , "close running servers and return any error" ))
318- }
319-
320- s .mu .RLock ()
321- shutdownSrvs (errs )
322- s .mu .RUnlock ()
323- echan <- errs
323+ handleErr (err )
324324 return
325325
326326 case err := <- hech : // when health check server returns, close running servers and return any error
327- if err != nil {
328- errs = append (errs , errors .Wrap (err , "close running servers and return any error" ))
329- }
330-
331- s .mu .RLock ()
332- shutdownSrvs (errs )
333- s .mu .RUnlock ()
334- echan <- errs
327+ handleErr (err )
335328 return
336329
337330 case err := <- dech : // when debug server returns, close running servers and return any error
338- if err != nil {
339- errs = append (errs , errors .Wrap (err , "close running servers and return any error" ))
340- }
341-
342- s .mu .RLock ()
343- shutdownSrvs (errs )
344- s .mu .RUnlock ()
345- echan <- errs
331+ handleErr (err )
346332 return
347-
348333 }
349334 }
350335 }()
@@ -364,7 +349,7 @@ func (s *server) dShutdown(ctx context.Context) error {
364349 return s .dsrv .Shutdown (dctx )
365350}
366351
367- // apiShutdown returns any error when shutdown the authorization proxy server.
352+ // apiShutdown returns any error when shutdown the authorization proxy API server.
368353// Before shutdown the authorization proxy server, it will sleep config.ShutdownDelay to prevent any issue from K8s
369354func (s * server ) apiShutdown (ctx context.Context ) error {
370355 time .Sleep (s .sdd )
@@ -373,7 +358,7 @@ func (s *server) apiShutdown(ctx context.Context) error {
373358 return s .srv .Shutdown (sctx )
374359}
375360
376- // apiShutdown returns any error when shutdown the authorization proxy server.
361+ // grpcShutdown returns any error when shutdown the authorization proxy gPRC server.
377362// Before shutdown the authorization proxy server, it will sleep config.ShutdownDelay to prevent any issue from K8s
378363func (s * server ) grpcShutdown () {
379364 time .Sleep (s .sdd )
0 commit comments