Automattic / Automattic/kue

Process won't exit after queue shutdown if client is saving a job

Open
#1,078 4 comments 0 reactions 0 assignees View on GitHub
Bug needs pull request
Dominant language
JavaScript
Stars
9.4k
Forks
858
PR merge metrics
No merged PRs in 30d

Description

`kue@0.11.6`

Test case:

```javascript
const test = require('blue-tape')
const kue = require('kue')

let queue

test('create queue', (t) => {
queue = kue.createQueue({
prefix: 'test-shutdown',
redis: {
host: 'localhost',
port: 6379
},
})
t.end()
})

test('enqueue', (t) => {
// don't block
queue
.create('job-type', { foo: 'bar' })
.save((err) => {
t.ok(!!err)
console.error(err)
})
t.end()
})

test('shutdown queue', (t) => {
queue.shutdown(0, (err) => {
t.error(err)
t.end()
})
})

test('the process will not exit :(', (t) => {
t.end()
})
```

Output (process does not exit):

```
$ tape test.js
TAP version 13
# create queue
# enqueue
# shutdown queue
ok 1 undefined
# the process will not exit :(
ok 2 should be truthy
{ AbortError
at handle_offline_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:846:15)
at RedisClient.internal_send_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:880:9)
at Multi.exec_transaction (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/multi.js:115:18)
at Job.state (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:702:9)
at Job. (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:869:10)
at callbackOrEmit (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:89:9)
at /Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:107:13
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9)
command: 'EXEC',
code: 'NR_CLOSED',
errors:
[ { AbortError
at handle_offline_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:846:15)
at RedisClient.internal_send_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:880:9)
at pipeline_transaction_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/multi.js:41:18)
at Multi.exec_transaction (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/multi.js:112:9)
at Job.state (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:702:9)
at Job. (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:869:10)
at callbackOrEmit (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:89:9)
at /Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:107:13
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9) command: 'HSET', code: 'NR_CLOSED', args: [Array], position: 0 },
{ AbortError
at handle_offline_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:846:15)
at RedisClient.internal_send_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:880:9)
at pipeline_transaction_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/multi.js:41:18)
at Multi.exec_transaction (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/multi.js:112:9)
at Job.state (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:702:9)
at Job. (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:869:10)
at callbackOrEmit (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:89:9)
at /Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:107:13
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9) command: 'ZADD', code: 'NR_CLOSED', args: [Array], position: 1 },
{ AbortError
at handle_offline_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:846:15)
at RedisClient.internal_send_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:880:9)
at pipeline_transaction_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/multi.js:41:18)
at Multi.exec_transaction (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/multi.js:112:9)
at Job.state (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:702:9)
at Job. (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:869:10)
at callbackOrEmit (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:89:9)
at /Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:107:13
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9) command: 'ZADD', code: 'NR_CLOSED', args: [Array], position: 2 },
{ AbortError
at handle_offline_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:846:15)
at RedisClient.internal_send_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/index.js:880:9)
at pipeline_transaction_command (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/multi.js:41:18)
at Multi.exec_transaction (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/multi.js:112:9)
at Job.state (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:702:9)
at Job. (/Users/olalonde/code/kue-shutdown-test/node_modules/kue/lib/queue/job.js:869:10)
at callbackOrEmit (/Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:89:9)
at /Users/olalonde/code/kue-shutdown-test/node_modules/redis/lib/utils.js:107:13
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9)
command: 'LPUSH',
code: 'NR_CLOSED',
args: [Array],
position: 3 } ] }
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Run the supplied tape test with Redis and reproduce the process that remains alive after queue.shutdown. Read lib/queue/job.js around Job.state, as shown in the stack trace, and trace the interaction between the in-flight save and shutdown. Done means the process exits after shutdown even when a save is still in progress, with the reported behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, redis
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.