diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-10-12 21:08:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-12 21:08:10 +0200 |
commit | 03095bd090e067ef1a2978a2107ec07ff3f95a2c (patch) | |
tree | a358550e152355529412e3247aeaefc2887db306 /pkg/api/server | |
parent | 65e156467b5cc40e14a578a6d916e4df902d0a99 (diff) | |
parent | 0459484bdf51b3aabc51f2ae82136b6b0f3d88ba (diff) | |
download | podman-03095bd090e067ef1a2978a2107ec07ff3f95a2c.tar.gz podman-03095bd090e067ef1a2978a2107ec07ff3f95a2c.tar.bz2 podman-03095bd090e067ef1a2978a2107ec07ff3f95a2c.zip |
Merge pull request #11927 from jwhonce/issues/11921
Fix CI flake on time of shutdown for API service
Diffstat (limited to 'pkg/api/server')
-rw-r--r-- | pkg/api/server/server.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/pkg/api/server/server.go b/pkg/api/server/server.go index 6e9578cd1..8c5c7aeeb 100644 --- a/pkg/api/server/server.go +++ b/pkg/api/server/server.go @@ -207,7 +207,7 @@ func (s *APIServer) setupSystemd() { func (s *APIServer) Serve() error { s.setupPprof() - if err := shutdown.Register("server", func(sig os.Signal) error { + if err := shutdown.Register("service", func(sig os.Signal) error { return s.Shutdown(true) }); err != nil { return err @@ -272,20 +272,24 @@ func (s *APIServer) setupPprof() { // Shutdown is a clean shutdown waiting on existing clients func (s *APIServer) Shutdown(halt bool) error { - if s.idleTracker.Duration == UnlimitedServiceDuration && !halt { - logrus.Debug("API service shutdown request ignored as Duration is UnlimitedService") + switch { + case halt: + logrus.Debug("API service forced shutdown, ignoring timeout Duration") + case s.idleTracker.Duration == UnlimitedServiceDuration: + logrus.Debug("API service shutdown request ignored as timeout Duration is UnlimitedService") return nil } shutdownOnce.Do(func() { - if logrus.IsLevelEnabled(logrus.DebugLevel) { - _, file, line, _ := runtime.Caller(1) - logrus.Debugf("API service shutdown by %s:%d, %d/%d connection(s)", - file, line, s.idleTracker.ActiveConnections(), s.idleTracker.TotalConnections()) - } + logrus.Debugf("API service shutdown, %d/%d connection(s)", + s.idleTracker.ActiveConnections(), s.idleTracker.TotalConnections()) // Gracefully shutdown server(s), duration of wait same as idle window - ctx, cancel := context.WithTimeout(context.Background(), s.idleTracker.Duration) + deadline := 1 * time.Second + if s.idleTracker.Duration > 0 { + deadline = s.idleTracker.Duration + } + ctx, cancel := context.WithTimeout(context.Background(), deadline) go func() { defer cancel() @@ -296,7 +300,6 @@ func (s *APIServer) Shutdown(halt bool) error { }() <-ctx.Done() }) - return nil } |