Skip to content

Commit 4e3c5cb

Browse files
authored
Merge branch 'master' into race-fix
2 parents 00e0ebe + 8d8dddd commit 4e3c5cb

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

xhttp/serve.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,23 @@ func Serve(ctx context.Context, shutdownTimeout time.Duration, s *http.Server, l
7070
serverClosed := make(chan struct{})
7171
var serverError error
7272
go func() {
73-
serverError = ss.ListenAndServe(l)
74-
close(serverClosed)
73+
serverError = ss.ListenAndServe(l)
74+
close(serverClosed)
7575
}()
7676

7777
select {
7878
case <-serverClosed:
79-
return serverError
79+
return serverError
8080
case <-ctx.Done():
81-
shutdownCtx, cancel := context.WithTimeout(xcontext.WithoutCancel(ctx), shutdownTimeout)
82-
defer cancel()
83-
err := ss.Shutdown(shutdownCtx)
84-
<-serverClosed // Wait for server to exit
85-
if err != nil {
86-
return err
87-
}
88-
return serverError
81+
shutdownCtx, cancel := context.WithTimeout(xcontext.WithoutCancel(ctx), shutdownTimeout)
82+
defer cancel()
83+
84+
err := ss.Shutdown(shutdownCtx)
85+
<-serverClosed // Wait for server to exit
86+
if err != nil {
87+
return err
88+
}
89+
return serverError
8990
}
90-
}
91+
92+
}

0 commit comments

Comments
 (0)