diff options
author | Valery Piashchynski <[email protected]> | 2020-03-06 01:16:25 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-03-06 01:16:25 +0300 |
commit | 617eb5a965fd70c150754bc661c4d19eb3a8d184 (patch) | |
tree | 89619d4c41b554cfa402e8b4b9c69a127d294c90 /service/container.go | |
parent | a208e27c9d8f4558328c3931c960f155a02e786f (diff) |
Add container with [ephemeral] plugin to the main
Fix wrong behaviour when plugin fails during serve
Diffstat (limited to 'service/container.go')
-rw-r--r-- | service/container.go | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/service/container.go b/service/container.go index 742b4c3b..3be90efb 100644 --- a/service/container.go +++ b/service/container.go @@ -162,27 +162,31 @@ func (c *container) Serve() error { done = make(chan interface{}, len(c.services)) ) + mu := &sync.Mutex{} + for _, e := range c.services { if e.hasStatus(StatusOK) && e.canServe() { - numServing++ + c.log.Debugf("[%s]: started", e.name) + go func(e *entry) { + mu.Lock() + e.setStatus(StatusServing) + numServing++ + mu.Unlock() + defer e.setStatus(StatusStopped) + + if err := e.svc.(Service).Serve(); err != nil { + c.log.Errorf("[%s]: %s", e.name, err) + done <- errors.Wrap(err, fmt.Sprintf("[%s]", e.name)) + } else { + done <- nil + } + }(e) } else { continue } - - c.log.Debugf("[%s]: started", e.name) - go func(e *entry) { - e.setStatus(StatusServing) - defer e.setStatus(StatusStopped) - - if err := e.svc.(Service).Serve(); err != nil { - c.log.Errorf("[%s]: %s", e.name, err) - done <- errors.Wrap(err, fmt.Sprintf("[%s]", e.name)) - } else { - done <- nil - } - }(e) } + mu.Lock() var serveErr error for i := 0; i < numServing; i++ { result := <-done @@ -198,6 +202,7 @@ func (c *container) Serve() error { serveErr = err } } + mu.Unlock() return serveErr } |