From e94d925711e8aee36a09568a41e180f3cae79bd3 Mon Sep 17 00:00:00 2001 From: yanggang Date: Tue, 27 Dec 2022 13:57:20 +0800 Subject: [PATCH] CRI sbserver: Prevent server reuse after Shutdown. Signed-off-by: yanggang --- pkg/cri/sbserver/service.go | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/pkg/cri/sbserver/service.go b/pkg/cri/sbserver/service.go index e19baec9a..8dd694d56 100644 --- a/pkg/cri/sbserver/service.go +++ b/pkg/cri/sbserver/service.go @@ -290,24 +290,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) }