summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-12 23:36:34 +0300
committerWolfy-J <[email protected]>2018-06-12 23:36:34 +0300
commit3126c203b10573f6b834b426edbe2e66b50eb9a2 (patch)
tree13cf7b879fb7fe6c733929c182f9ada2fb125910
parent47aa87a1cd438c6c99a4640f6af60fd408b5c3bc (diff)
fixing worker allocation loop
-rw-r--r--server.go2
-rw-r--r--static_pool.go4
-rw-r--r--static_pool_test.go5
3 files changed, 7 insertions, 4 deletions
diff --git a/server.go b/server.go
index efdeaca2..7a115a81 100644
--- a/server.go
+++ b/server.go
@@ -123,13 +123,13 @@ func (srv *Server) Reconfigure(cfg *ServerConfig) error {
srv.mu.Unlock()
pool, err := NewPool(cfg.makeCommand(), srv.factory, *cfg.Pool)
+ srv.pool.Listen(srv.poolListener)
if err != nil {
return err
}
srv.mu.Lock()
srv.cfg.Pool, srv.pool = cfg.Pool, pool
- srv.pool.Listen(srv.poolListener)
srv.mu.Unlock()
srv.throw(EventPoolConstruct, pool)
diff --git a/static_pool.go b/static_pool.go
index 18bfaf60..24665c01 100644
--- a/static_pool.go
+++ b/static_pool.go
@@ -169,13 +169,15 @@ func (p *StaticPool) allocateWorker() (w *Worker, err error) {
return nil, fmt.Errorf("worker timeout (%s)", p.cfg.AllocateTimeout)
case w = <-p.free:
timeout.Stop()
+
if w.State().Value() != StateReady {
continue
}
+ return w, nil
}
}
- return w, nil
+ return nil, fmt.Errorf("all workers are dead (%v)", p.cfg.NumWorkers)
}
// release releases or replaces the worker.
diff --git a/static_pool_test.go b/static_pool_test.go
index 548fb126..231bc71b 100644
--- a/static_pool_test.go
+++ b/static_pool_test.go
@@ -2,13 +2,13 @@ package roadrunner
import (
"github.com/stretchr/testify/assert"
- "log"
"os/exec"
"runtime"
"strconv"
- "sync"
"testing"
"time"
+ "sync"
+ "log"
)
var cfg = Config{
@@ -266,6 +266,7 @@ func Test_StaticPool_Replace_Worker(t *testing.T) {
}
}
+
// identical to replace but controlled on worker side
func Test_StaticPool_Stop_Worker(t *testing.T) {
p, err := NewPool(