diff options
Diffstat (limited to 'service/http/service.go')
-rw-r--r-- | service/http/service.go | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/service/http/service.go b/service/http/service.go index 3d200845..cef019b3 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -7,6 +7,7 @@ import ( "github.com/spiral/roadrunner/service/rpc" "net/http" "sync" + "sync/atomic" ) // ID contains default svc name. @@ -21,10 +22,11 @@ type Service struct { lsns []func(event int, ctx interface{}) mdws []middleware - mu sync.Mutex - rr *roadrunner.Server - srv *Handler - http *http.Server + mu sync.Mutex + rr *roadrunner.Server + stopping int32 + srv *Handler + http *http.Server } // AddMiddleware adds new net/http middleware. @@ -95,6 +97,11 @@ func (s *Service) Serve() error { // Stop stops the svc. func (s *Service) Stop() { + if atomic.LoadInt32(&s.stopping) != 0 { + // already stopping + return + } + s.mu.Lock() defer s.mu.Unlock() if s.http == nil { @@ -121,9 +128,11 @@ func (s *Service) listener(event int, ctx interface{}) { } if event == roadrunner.EventServerFailure { - // attempting rr server restart - if err := s.rr.Start(); err != nil { - s.Stop() + if atomic.LoadInt32(&s.stopping) != 0 { + // attempting rr server restart + if err := s.rr.Start(); err != nil { + s.Stop() + } } } } |