tobiasc/local-node-lambda

Timer object leaks

Closed this issue · 3 comments

The setTimeout() "leaks" in some way. Atleast when I am running within a gulp mocha test suite. If you cancel the timeout it works better.
So from

    setTimeout(function(){
        timeoutReached = true;
        callback(new Error("Task timed out after " + (timeout / 1000).toFixed(2) + " seconds"));
    }, timeout); 

    context.setCallback(function (err, message) {
        if (!timeoutReached) {
            callback(err, message);
        }
    });

    // execute lambda function
    if (lambdaFunc[handler]) {
        lambdaFunc[handler](eventObj, context);
    } else {
        callback(new Error('Could not find Lambda handler'));
    }

To:

var timer = setTimeout(function(){
        timeoutReached = true;
        callback(new Error("Task timed out after " + (timeout / 1000).toFixed(2) + " seconds"));
    }, timeout); 

    context.setCallback(function (err, message) {
        if (!timeoutReached) {
            callback(err, message);
        }
    });

    // execute lambda function
    if (lambdaFunc[handler]) {
        lambdaFunc[handler](eventObj, context);
        clearTimeout(timer);
    } else {
        callback(new Error('Could not find Lambda handler'));
    }
    clearTimeout(timer);

Could you possible do that change? Maybe if I make a pull request?

Closing this issue as I've merged your PR (#5). Thanks again for the PR & the creating the issue :)

Thank you! Do you intend to publish an updated version on NPM?

Good point, let me bump the version number