fix: fixed race condition between http.Server ListenAndServe & Shutdown, now service crash during startup correctly closes http server every time

This commit is contained in:
Torkel Ödegaard
2018-05-02 19:56:15 +02:00
parent d04ad835e2
commit 23655315b8
3 changed files with 29 additions and 9 deletions
+2
View File
@@ -71,6 +71,8 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
// handle http shutdown on server context done
go func() {
<-ctx.Done()
// Hacky fix for race condition between ListenAndServe and Shutdown
time.Sleep(time.Millisecond * 100)
if err := hs.httpSrv.Shutdown(context.Background()); err != nil {
hs.log.Error("Failed to shutdown server", "error", err)
}