Skip to content

Commit b88c69b

Browse files
committed
Revert "race issue fix"
This reverts commit b70cdfa.
1 parent 8d8dddd commit b88c69b

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

xhttp/serve.go

+7-14
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,18 @@ func Serve(ctx context.Context, shutdownTimeout time.Duration, s *http.Server, l
2727
return ctx
2828
}
2929

30-
serverClosed := make(chan struct{})
31-
var serverError error
30+
done := make(chan error, 1)
3231
go func() {
33-
serverError = s.Serve(l)
34-
close(serverClosed)
32+
done <- s.Serve(l)
3533
}()
3634

3735
select {
38-
case <-serverClosed:
39-
return serverError
36+
case err := <-done:
37+
return err
4038
case <-ctx.Done():
41-
shutdownCtx, cancel := context.WithTimeout(xcontext.WithoutCancel(ctx), shutdownTimeout)
39+
ctx = xcontext.WithoutCancel(ctx)
40+
ctx, cancel := context.WithTimeout(ctx, shutdownTimeout)
4241
defer cancel()
43-
44-
err := s.Shutdown(shutdownCtx)
45-
<-serverClosed // Wait for server to exit
46-
if err != nil {
47-
return err
48-
}
49-
return serverError
42+
return s.Shutdown(ctx)
5043
}
5144
}

0 commit comments

Comments
 (0)