summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-05-06 20:58:34 +0300
committerGitHub <[email protected]>2021-05-06 20:58:34 +0300
commit3bd2be271d1ac13f77058158a0b272e611936b82 (patch)
tree19a271465b7ac5a045b9078ab22c600645dcf6a5
parent009b7009885d8a15e6fa6c7e78436087b2f20129 (diff)
parent08dc04c6f8d8a5b5507b8d95c33f413c4eec3203 (diff)
#662 fix(bug): RR does not respect `debug` mode when `exec_ttl` is set
#662 fix(bug): RR does not respect `debug` mode when `exec_ttl` is set
-rw-r--r--.github/workflows/linux.yml1
-rw-r--r--CHANGELOG.md1
-rwxr-xr-xpkg/pool/static_pool.go22
-rw-r--r--pkg/pool/supervisor_test.go28
4 files changed, 50 insertions, 2 deletions
diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml
index bb7d646b..89173b3f 100644
--- a/.github/workflows/linux.yml
+++ b/.github/workflows/linux.yml
@@ -82,7 +82,6 @@ jobs:
- uses: codecov/codecov-action@v1 # Docs: <https://github.com/codecov/codecov-action>
with:
- token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage-ci/summary.txt
fail_ci_if_error: false
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3ed7c7bb..1c2d16ec 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ v2.2.0 (11.05.2021)
## 🩹 Fixes:
- 🐛 Fix: issue with wrong ordered middlewares (reverse). Now the order is correct.
+- 🐛 Fix: issue when RR fails if a user sets `debug` mode with the `exec_ttl` supervisor option.
---
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),