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

Loading…
Cancel
Save