Merge pull request #9 from marko-gacesa/graceful-shutdown

fixed: graceful shutdown of http servers
pull/11/head
TP Honey 3 years ago committed by GitHub
commit 93da92dbb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -44,10 +44,8 @@ func (s Server) listenAndServe(ctx context.Context) error {
Handler: s.Handler, Handler: s.Handler,
} }
g.Go(func() error { g.Go(func() error {
select { <-ctx.Done()
case <-ctx.Done(): return s1.Shutdown(context.Background())
return s1.Shutdown(ctx)
}
}) })
g.Go(func() error { g.Go(func() error {
return s1.ListenAndServe() return s1.ListenAndServe()
@ -75,12 +73,18 @@ func (s Server) listenAndServeTLS(ctx context.Context) error {
) )
}) })
g.Go(func() error { g.Go(func() error {
select { <-ctx.Done()
case <-ctx.Done():
s1.Shutdown(ctx) var gShutdown errgroup.Group
s2.Shutdown(ctx)
return nil gShutdown.Go(func() error {
} return s1.Shutdown(context.Background())
})
gShutdown.Go(func() error {
return s2.Shutdown(context.Background())
})
return gShutdown.Wait()
}) })
return g.Wait() return g.Wait()
} }
@ -114,12 +118,18 @@ func (s Server) listenAndServeAcme(ctx context.Context) error {
return s2.ListenAndServeTLS("", "") return s2.ListenAndServeTLS("", "")
}) })
g.Go(func() error { g.Go(func() error {
select { <-ctx.Done()
case <-ctx.Done():
s1.Shutdown(ctx) var gShutdown errgroup.Group
s2.Shutdown(ctx)
return nil gShutdown.Go(func() error {
} return s1.Shutdown(context.Background())
})
gShutdown.Go(func() error {
return s2.Shutdown(context.Background())
})
return gShutdown.Wait()
}) })
return g.Wait() return g.Wait()
} }

Loading…
Cancel
Save