Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle python's 120 exit code #340

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 4.20.3

- Treat a rare python exit code of 120 as a special case of exit code 3 (#340).

### 4.20.2

- Using InChina instead of NotInChina Cloudformation condition: https://github.com/mapbox/ecs-watchbot/pull/329
Expand Down
3 changes: 3 additions & 0 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class Worker {
if (results.code === 0) return await this.success(results);
if (results.code === 3) return await this.ignore(results);
if (results.code === 4) return await this.noop(results);
// Rarely, python may set an exit code of 120 during its cleanup phase.
// We should not retry in this case.
if (results.code === 120) return await this.ignore(results);
return await this.fail(results);
} catch (err) {
clearInterval(heartbeatTimeout);
Expand Down
28 changes: 28 additions & 0 deletions test/worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,34 @@ test('[worker] waitFor, exit 4', async (assert) => {
assert.end();
});

test('[worker] waitFor, exit 120', async (assert) => {
const logger = stubber(Logger).setup();
logger.log.restore();
logger.stream.restore();
const message = sinon.createStubInstance(Message);
message.env = { Message: 'forty bananas', SentTimestamp: '2019-02-09T21:57:55.000Z' };
const options = { command: 'exit 120', volumes: ['/tmp'] };
const worker = new Worker(message, options);

sinon.spy(child_process, 'spawn');

try {
await worker.waitFor();
} catch (err) {
assert.ifError(err, 'failed');
}

const results = logger.workerFailure.args[0][0];
assert.equal(results.code, 120, 'logged worker failure exit code');
assert.ok(results.duration, 'logged worker failure duration');
assert.ok(results.response_duration, 'logged worker response duration');
assert.equal(message.complete.callCount, 1, 'calls message.complete()');

child_process.spawn.restore();
logger.teardown();
assert.end();
});

sgillies marked this conversation as resolved.
Show resolved Hide resolved
test('[worker] waitFor, child_process.spawn failure', async (assert) => {
const logger = stubber(Logger).setup();
logger.log.restore();
Expand Down