Skip to content

Commit d319450

Browse files
Update serve.go
1 parent 44c011a commit d319450

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

xhttp/serve.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ func Serve(ctx context.Context, shutdownTimeout time.Duration, s *http.Server, l
3535
select {
3636
case err := <-done:
3737
return err
38+
3839
case <-ctx.Done():
39-
ctx = xcontext.WithoutCancel(ctx)
40-
ctx, cancel := context.WithTimeout(ctx, shutdownTimeout)
40+
41+
shutdownCtx := xcontext.WithoutCancel(ctx)
42+
shutdownCtx, cancel := context.WithTimeout(shutdownCtx, shutdownTimeout)
4143
defer cancel()
42-
return s.Shutdown(ctx)
44+
shutdownErr := s.Shutdown(shutdownCtx)
45+
serveErr := <-done
46+
if serveErr != nil && serveErr != http.ErrServerClosed {
47+
return serveErr
48+
}
49+
50+
return shutdownErr
4351
}
4452
}

0 commit comments

Comments
 (0)