summaryrefslogtreecommitdiff
path: root/service/http/service.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-23 17:06:07 +0300
committerWolfy-J <[email protected]>2018-06-23 17:06:07 +0300
commit80bd89f91fd0055579717f3cc65b39176eb09000 (patch)
tree223e1980e580137b0b937cf6d8464aa59cc8733e /service/http/service.go
parentddf2ce2ca7d90d6cddf7d49e973ea4ec17f8477a (diff)
realtime error handling and displaying
Diffstat (limited to 'service/http/service.go')
-rw-r--r--service/http/service.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/service/http/service.go b/service/http/service.go
index 3d200845..d98a4596 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
+ inStopping int32
+ srv *Handler
+ http *http.Server
}
// AddMiddleware adds new net/http middleware.
@@ -95,9 +97,12 @@ func (s *Service) Serve() error {
// Stop stops the svc.
func (s *Service) Stop() {
+ atomic.AddInt32(&s.inStopping, 1)
+ defer atomic.AddInt32(&s.inStopping, -1)
+
s.mu.Lock()
defer s.mu.Unlock()
- if s.http == nil {
+ if s.http == nil || s.stopping() {
return
}
@@ -115,12 +120,16 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.srv.ServeHTTP(w, r)
}
+func (s *Service) stopping() bool {
+ return atomic.LoadInt32(&s.inStopping) != 0
+}
+
func (s *Service) listener(event int, ctx interface{}) {
for _, l := range s.lsns {
l(event, ctx)
}
- if event == roadrunner.EventServerFailure {
+ if event == roadrunner.EventServerFailure && !s.stopping() {
// attempting rr server restart
if err := s.rr.Start(); err != nil {
s.Stop()