mirror of https://github.com/containers/podman.git
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>
This commit is contained in:
parent
3d37dc639d
commit
997e3c8863
|
|
@ -143,7 +143,6 @@ func runREST(r *libpod.Runtime, uri string, timeout time.Duration) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "unable to create socket %s", uri)
|
return errors.Wrapf(err, "unable to create socket %s", uri)
|
||||||
}
|
}
|
||||||
defer l.Close()
|
|
||||||
listener = &l
|
listener = &l
|
||||||
}
|
}
|
||||||
server, err := api.NewServerWithSettings(r, timeout, listener)
|
server, err := api.NewServerWithSettings(r, timeout, listener)
|
||||||
|
|
|
||||||
|
|
@ -140,36 +140,31 @@ func newServer(runtime *libpod.Runtime, duration time.Duration, listener *net.Li
|
||||||
func (s *APIServer) Serve() error {
|
func (s *APIServer) Serve() error {
|
||||||
// stalker to count the connections. Should the timer expire it will shutdown the service.
|
// stalker to count the connections. Should the timer expire it will shutdown the service.
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for delta := range s.ConnectionCh {
|
||||||
select {
|
switch delta {
|
||||||
case delta := <-s.ConnectionCh:
|
case EnterHandler:
|
||||||
// Always stop the current timer, things will change...
|
|
||||||
s.Timer.Stop()
|
s.Timer.Stop()
|
||||||
switch delta {
|
s.ActiveConnections += 1
|
||||||
case EnterHandler:
|
s.TotalConnections += 1
|
||||||
s.ActiveConnections += 1
|
case ExitHandler:
|
||||||
s.TotalConnections += 1
|
s.Timer.Stop()
|
||||||
case ExitHandler:
|
s.ActiveConnections -= 1
|
||||||
s.ActiveConnections -= 1
|
if s.ActiveConnections == 0 {
|
||||||
if s.ActiveConnections == 0 {
|
// Server will be shutdown iff the timer expires before being reset or stopped
|
||||||
// Server will be shutdown iff the timer expires before being reset or stopped
|
s.Timer = time.AfterFunc(s.Duration, func() {
|
||||||
s.Timer = time.AfterFunc(s.Duration, func() {
|
if err := s.Shutdown(); err != nil {
|
||||||
if err := s.Shutdown(); err != nil {
|
logrus.Errorf("Failed to shutdown APIServer: %v", err)
|
||||||
logrus.Errorf("Failed to shutdown APIServer: %v", err)
|
os.Exit(1)
|
||||||
os.Exit(1)
|
}
|
||||||
}
|
})
|
||||||
})
|
} else {
|
||||||
} else {
|
|
||||||
s.Timer.Reset(s.Duration)
|
|
||||||
}
|
|
||||||
case NOOPHandler:
|
|
||||||
// push the check out another duration...
|
|
||||||
s.Timer.Reset(s.Duration)
|
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:
|
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() {
|
go func() {
|
||||||
err := s.Server.Shutdown(ctx)
|
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())
|
logrus.Errorf("Failed to cleanly shutdown APIServer: %s", err.Error())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue