aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/server/server.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-02-25 10:55:17 -0700
committerJhon Honce <jhonce@redhat.com>2020-02-25 11:04:20 -0700
commit997e3c886383aab4cdf86c386469d20ac589e158 (patch)
treee798c7359228f9d23436d4683b9bd54f4f289f04 /pkg/api/server/server.go
parent3d37dc639d87e4469a6457cf4592ff5b773d0777 (diff)
downloadpodman-997e3c886383aab4cdf86c386469d20ac589e158.tar.gz
podman-997e3c886383aab4cdf86c386469d20ac589e158.tar.bz2
podman-997e3c886383aab4cdf86c386469d20ac589e158.zip
Remove 1 sec delay
* Stop closing net.Listener() twice on interrupt * Do not report error if closing server twice Fixes #5311 Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'pkg/api/server/server.go')
-rw-r--r--pkg/api/server/server.go49
1 files changed, 22 insertions, 27 deletions
diff --git a/pkg/api/server/server.go b/pkg/api/server/server.go
index e7b2a5525..a5922e5d7 100644
--- a/pkg/api/server/server.go
+++ b/pkg/api/server/server.go
@@ -140,36 +140,31 @@ func newServer(runtime *libpod.Runtime, duration time.Duration, listener *net.Li
func (s *APIServer) Serve() error {
// stalker to count the connections. Should the timer expire it will shutdown the service.
go func() {
- for {
- select {
- case delta := <-s.ConnectionCh:
- // Always stop the current timer, things will change...
+ for delta := range s.ConnectionCh {
+ switch delta {
+ case EnterHandler:
s.Timer.Stop()
- switch delta {
- case EnterHandler:
- s.ActiveConnections += 1
- s.TotalConnections += 1
- case ExitHandler:
- s.ActiveConnections -= 1
- if s.ActiveConnections == 0 {
- // Server will be shutdown iff the timer expires before being reset or stopped
- s.Timer = time.AfterFunc(s.Duration, func() {
- if err := s.Shutdown(); err != nil {
- logrus.Errorf("Failed to shutdown APIServer: %v", err)
- os.Exit(1)
- }
- })
- } else {
- s.Timer.Reset(s.Duration)
- }
- case NOOPHandler:
- // push the check out another duration...
+ s.ActiveConnections += 1
+ s.TotalConnections += 1
+ case ExitHandler:
+ s.Timer.Stop()
+ s.ActiveConnections -= 1
+ if s.ActiveConnections == 0 {
+ // Server will be shutdown iff the timer expires before being reset or stopped
+ s.Timer = time.AfterFunc(s.Duration, func() {
+ if err := s.Shutdown(); err != nil {
+ logrus.Errorf("Failed to shutdown APIServer: %v", err)
+ os.Exit(1)
+ }
+ })
+ } else {
s.Timer.Reset(s.Duration)
- default:
- logrus.Errorf("ConnectionCh received unsupported input %d", delta)
}
+ case NOOPHandler:
+ // push the check out another duration...
+ s.Timer.Reset(s.Duration)
default:
- time.Sleep(1 * time.Second)
+ logrus.Errorf("ConnectionCh received unsupported input %d", delta)
}
}
}()
@@ -212,7 +207,7 @@ func (s *APIServer) Shutdown() error {
go func() {
err := s.Server.Shutdown(ctx)
- if err != nil && err != context.Canceled {
+ if err != nil && err != context.Canceled && err != http.ErrServerClosed {
logrus.Errorf("Failed to cleanly shutdown APIServer: %s", err.Error())
}
}()