Skip to content

Commit 97ed972

Browse files
committed
Fix max idle overtaking lambda timeout
1 parent 16953a0 commit 97ed972

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/lambda.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ function forkLambda(
231231
invoke(event, context, callback) {
232232
if (idle_timer) {
233233
clearTimeout(idle_timer);
234+
idle_timer = null;
234235
}
235-
idle_timer = setTimeout(kill, max_idle);
236236
const i = ++id;
237237
const ms_timeout = timeout * 1000;
238238
if (!inspect_lambda) {
@@ -247,6 +247,8 @@ function forkLambda(
247247
clearTimeout(timeout_timer);
248248
if (graceful_shutdown) {
249249
kill();
250+
} else if (!err) {
251+
idle_timer = setTimeout(kill, max_idle);
250252
}
251253
callback(err, value);
252254
};

test/lambda-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,23 @@ describe('lambda', () => {
476476
});
477477
});
478478

479+
it('kills lambda after configured timeout if larger than max_idle', (done) => {
480+
sinon.stub(log, 'warn');
481+
482+
lambda = Lambda.create({
483+
max_idle: 25,
484+
env: {
485+
AWS_PROFILE: 'local'
486+
}
487+
});
488+
489+
lambda.invoke('timeout-file', {}, (err) => {
490+
assert.json(err, { code: 'E_TIMEOUT' });
491+
assert.calledOnce(log.warn);
492+
done();
493+
});
494+
});
495+
479496
it('does not fail to talk to lambda after two where killed', (done) => {
480497
sinon.stub(log, 'warn');
481498

0 commit comments

Comments
 (0)