fixed: graceful shutdown of http servers

pull/9/head
Marko Gaćeša 3 years ago
parent 874c664428
commit 60690fc728

@ -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