diff options
author | Valery Piashchynski <[email protected]> | 2021-12-15 01:02:39 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-12-15 01:02:39 +0300 |
commit | ff1401e97a9d1f3c059a60acbcae3f4507dcfe03 (patch) | |
tree | 7076f4712f9b4dbfb6d3a1bae3f4ba812d92a89d /pool | |
parent | f2c79017ae5759256b03ec58b608f298a29e4b96 (diff) | |
parent | 1bcb131c1ace6bdb47123cf05e4943ac3c4744c4 (diff) |
[#872]: bug(static_pool, debug mode): worker exited immediately after obtaining the response
Diffstat (limited to 'pool')
-rwxr-xr-x | pool/static_pool.go | 18 | ||||
-rw-r--r-- | pool/supervisor_test.go | 7 |
2 files changed, 19 insertions, 6 deletions
diff --git a/pool/static_pool.go b/pool/static_pool.go index 9897b9e7..4906788f 100755 --- a/pool/static_pool.go +++ b/pool/static_pool.go @@ -318,8 +318,7 @@ func (sp *StaticPool) execDebug(p *payload.Payload) (*payload.Payload, error) { }() // destroy the worker - sw.State().Set(worker.StateDestroyed) - err = sw.Kill() + err = sw.Stop() if err != nil { sp.events.Send(events.NewEvent(events.EventWorkerError, pluginName, fmt.Sprintf("error: %s, worker's pid: %d", err, sw.Pid()))) return nil, err @@ -337,8 +336,19 @@ func (sp *StaticPool) execDebugWithTTL(ctx context.Context, p *payload.Payload) // redirect call to the worker with TTL r, err := sw.ExecWithTTL(ctx, p) - if stopErr := sw.Stop(); stopErr != nil { - sp.events.Send(events.NewEvent(events.EventWorkerError, pluginName, fmt.Sprintf("error: %s, pid: %d", err, sw.Pid()))) + if err != nil { + return nil, err + } + + go func() { + // read the exit status to prevent process to be a zombie + _ = sw.Wait() + }() + + err = sw.Stop() + if err != nil { + sp.events.Send(events.NewEvent(events.EventWorkerError, pluginName, fmt.Sprintf("error: %s, worker's pid: %d", err, sw.Pid()))) + return nil, err } return r, err diff --git a/pool/supervisor_test.go b/pool/supervisor_test.go index eb3c37dd..98af918a 100644 --- a/pool/supervisor_test.go +++ b/pool/supervisor_test.go @@ -211,18 +211,21 @@ func TestSupervisedPool_Idle(t *testing.T) { Body: []byte("foo"), }) - assert.Nil(t, err) + assert.NoError(t, err) assert.Empty(t, resp.Body) assert.Empty(t, resp.Context) time.Sleep(time.Second * 5) // worker should be marked as invalid and reallocated - _, err = p.Exec(&payload.Payload{ + rsp, err := p.Exec(&payload.Payload{ Context: []byte(""), Body: []byte("foo"), }) assert.NoError(t, err) + require.NotNil(t, rsp) + time.Sleep(time.Second * 2) + require.Len(t, p.Workers(), 1) // should be new worker with new pid assert.NotEqual(t, pid, p.Workers()[0].Pid()) p.Destroy(context.Background()) |