summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server.go12
-rw-r--r--server_test.go2
-rw-r--r--static_pool.go6
3 files changed, 10 insertions, 10 deletions
diff --git a/server.go b/server.go
index 45b4597c..4ffdf367 100644
--- a/server.go
+++ b/server.go
@@ -127,11 +127,12 @@ func (s *Server) Reconfigure(cfg *ServerConfig) error {
s.mu.Unlock()
pool, err := NewPool(cfg.makeCommand(), s.factory, *cfg.Pool)
- s.pool.Listen(s.poolListener)
if err != nil {
return err
}
+ s.pool.Listen(s.poolListener)
+
s.mu.Lock()
s.cfg.Pool, s.pool = cfg.Pool, pool
s.mu.Unlock()
@@ -177,23 +178,22 @@ func (s *Server) Pool() Pool {
// AddListener pool events.
func (s *Server) poolListener(event int, ctx interface{}) {
- // bypassing to user specified lsn
- s.throw(event, ctx)
-
if event == EventPoolError {
// pool failure, rebuilding
if err := s.Reset(); err != nil {
s.mu.Lock()
- defer s.mu.Unlock()
-
s.started = false
s.pool = nil
s.factory = nil
+ s.mu.Unlock()
// everything is dead, this is recoverable but heavy state
s.throw(EventServerFailure, err)
}
}
+
+ // bypassing to user specified lsn
+ s.throw(event, ctx)
}
// throw invokes event handler if any.
diff --git a/server_test.go b/server_test.go
index 0ae06713..13cacc2c 100644
--- a/server_test.go
+++ b/server_test.go
@@ -211,7 +211,7 @@ func TestServer_ServerFailure(t *testing.T) {
failure := make(chan interface{})
srv.Listen(func(e int, ctx interface{}) {
if e == EventServerFailure {
- close(failure)
+ failure <- nil
}
})
diff --git a/static_pool.go b/static_pool.go
index 80847f6e..42913b28 100644
--- a/static_pool.go
+++ b/static_pool.go
@@ -257,11 +257,11 @@ func (p *StaticPool) watchWorker(w *Worker) {
return
}
- p.throw(EventWorkerError, WorkerError{Worker: w, Caused: err})
-
// possible situation when major error causes all PHP scripts to die (for example dead DB)
if len(p.Workers()) == 0 {
- p.throw(EventPoolError, fmt.Errorf("unable to replace (last worker): %s", err))
+ p.throw(EventPoolError, err)
+ } else {
+ p.throw(EventWorkerError, WorkerError{Worker: w, Caused: err})
}
}
}