diff options
author | Valery Piashchynski <[email protected]> | 2021-05-06 20:02:48 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-05-06 20:02:48 +0300 |
commit | 797e25b47ef2e8aa01c1ded697fc0fd65d0bf511 (patch) | |
tree | 7cc360a96aef8b437a5e703b244ab2643c9b6f86 /pkg | |
parent | 009b7009885d8a15e6fa6c7e78436087b2f20129 (diff) |
- Fix bug with exec_ttl
- Update CHANGELOG
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'pkg')
-rwxr-xr-x | pkg/pool/static_pool.go | 22 | ||||
-rw-r--r-- | pkg/pool/supervisor_test.go | 28 |
2 files changed, 49 insertions, 1 deletions
diff --git a/pkg/pool/static_pool.go b/pkg/pool/static_pool.go index 06005d98..6ef2373a 100755 --- a/pkg/pool/static_pool.go +++ b/pkg/pool/static_pool.go @@ -170,6 +170,10 @@ func (sp *StaticPool) Exec(p payload.Payload) (payload.Payload, error) { // Be careful, sync with pool.Exec method func (sp *StaticPool) execWithTTL(ctx context.Context, p payload.Payload) (payload.Payload, error) { const op = errors.Op("static_pool_exec_with_context") + if sp.cfg.Debug { + return sp.execDebugWithTTL(ctx, p) + } + ctxAlloc, cancel := context.WithTimeout(ctx, sp.cfg.AllocateTimeout) defer cancel() w, err := sp.getWorker(ctxAlloc, op) @@ -243,7 +247,6 @@ func defaultErrEncoder(sp *StaticPool) ErrorEncoder { return func(err error, w worker.BaseProcess) (payload.Payload, error) { const op = errors.Op("error encoder") // just push event if on any stage was timeout error - switch { case errors.Is(errors.ExecTTL, err): sp.events.Push(events.PoolEvent{Event: events.EventExecTTL, Payload: errors.E(op, err)}) @@ -296,14 +299,31 @@ func (sp *StaticPool) newPoolAllocator(ctx context.Context, timeout time.Duratio } } +// execDebug used when debug mode was not set and exec_ttl is 0 func (sp *StaticPool) execDebug(p payload.Payload) (payload.Payload, error) { sw, err := sp.allocator() if err != nil { return payload.Payload{}, err } + // redirect call to the workers exec method (without ttl) r, err := sw.Exec(p) + if stopErr := sw.Stop(); stopErr != nil { + sp.events.Push(events.WorkerEvent{Event: events.EventWorkerError, Worker: sw, Payload: err}) + } + + return r, err +} + +// execDebugWithTTL used when user set debug mode and exec_ttl +func (sp *StaticPool) execDebugWithTTL(ctx context.Context, p payload.Payload) (payload.Payload, error) { + sw, err := sp.allocator() + if err != nil { + return payload.Payload{}, err + } + // redirect call to the worker with TTL + r, err := sw.ExecWithTTL(ctx, p) if stopErr := sw.Stop(); stopErr != nil { sp.events.Push(events.WorkerEvent{Event: events.EventWorkerError, Worker: sw, Payload: err}) } diff --git a/pkg/pool/supervisor_test.go b/pkg/pool/supervisor_test.go index d7e97fdd..dc307c33 100644 --- a/pkg/pool/supervisor_test.go +++ b/pkg/pool/supervisor_test.go @@ -53,6 +53,34 @@ func TestSupervisedPool_Exec(t *testing.T) { p.Destroy(context.Background()) } +// This test should finish without freezes +func TestSupervisedPool_ExecWithDebugMode(t *testing.T) { + var cfgSupervised = cfgSupervised + cfgSupervised.Debug = true + + ctx := context.Background() + p, err := Initialize( + ctx, + func() *exec.Cmd { return exec.Command("php", "../../tests/memleak.php", "pipes") }, + pipe.NewPipeFactory(), + cfgSupervised, + ) + + assert.NoError(t, err) + assert.NotNil(t, p) + + for i := 0; i < 100; i++ { + time.Sleep(time.Millisecond * 100) + _, err = p.Exec(payload.Payload{ + Context: []byte(""), + Body: []byte("foo"), + }) + assert.NoError(t, err) + } + + p.Destroy(context.Background()) +} + func TestSupervisedPool_ExecTTL_TimedOut(t *testing.T) { var cfgExecTTL = Config{ NumWorkers: uint64(1), |