Skip to content

Commit

Permalink
Merge pull request containerd#7165 from zouyee/nit
Browse files Browse the repository at this point in the history
prevent Server reuse after a Shutdown
  • Loading branch information
dmcgowan committed Dec 22, 2022
2 parents 341a494 + 20e7b39 commit b3b7981
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions pkg/cri/server/service.go
Expand Up @@ -287,24 +287,10 @@ func (c *criService) Run() error {
eventMonitorErr = err
}
logrus.Info("Event monitor stopped")
// There is a race condition with http.Server.Serve.
// When `Close` is called at the same time with `Serve`, `Close`
// may finish first, and `Serve` may still block.
// See https://github.com/golang/go/issues/20239.
// Here we set a 2 second timeout for the stream server wait,
// if it timeout, an error log is generated.
// TODO(random-liu): Get rid of this after https://github.com/golang/go/issues/20239
// is fixed.
const streamServerStopTimeout = 2 * time.Second
select {
case err := <-streamServerErrCh:
if err != nil {
streamServerErr = err
}
logrus.Info("Stream server stopped")
case <-time.After(streamServerStopTimeout):
logrus.Errorf("Stream server is not stopped in %q", streamServerStopTimeout)
if err := <-streamServerErrCh; err != nil {
streamServerErr = err
}
logrus.Info("Stream server stopped")
if eventMonitorErr != nil {
return fmt.Errorf("event monitor error: %w", eventMonitorErr)
}
Expand Down

0 comments on commit b3b7981

Please sign in to comment.