-
Notifications
You must be signed in to change notification settings - Fork 30
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
Socket connections requires set context.callbackWaitsForEmptyEventLoop to false #426
Comments
Break API Pros:
Cons:
Create another entrypoint Pros:
Cons:
|
Great description @hugosenari. I have a doubt on the expected behaviour, where you mention:
In my experience, whenever I open up a socket connection, even without Laconia, I will need to set callbackWaitsForEmptyEventLoop to false, especially if I want to freeze the connection. See also this comment, or this post. Otherwise, it will timeout, which is the expected behaviour from AWS Lambda. |
Almost one year later... sorry :) Here goes my tests results. Promise + Connection = Success
Callback - Connection = Success
Callback + Connection = Timeout:
Promise Code: const net = require('net');
const client = net.createConnection(53, '1.1.1.1');
console.log('connecting');
exports.handler = async (event) => {
const response = await {
statusCode: 200,
body: JSON.stringify(`
Hello from Lambda!
${client.destroyed}
${client.remoteAddress}
${client.write('olar')}
`),
};
console.log(response.body);
return response;
}; Callback Code: const net = require('net');
const client = net.createConnection(53, '1.1.1.1');
console.log('connecting');
exports.handler = (event, ctx, cb) => {
const response = {
statusCode: 200,
body: JSON.stringify(`
Hello from Lambda!
${client.destroyed}
${client.remoteAddress}
${client.write('olar')}
`),
};
console.log(response.body);
return cb(null, response);
}; |
Describe the bug
When my code leaves one open connection (ie: with some DBs), AWS Lambda throws timeout, even after my function run.
To Reproduce
Make any code that uses socket connections (ie: MySQL, Mongodb...);
Resolves function with some value;
And leaves that connection open for the next lambda function call.
Expected behavior
Since using promise to resolve function without laconia doesn't trows timeout.
I would expect the same with it.
Actual behavior
AWS Lambda throws timeout, even after my function resolves.
Additional context
Correct behavior (#48) would break laconia/batch and maybe others user cases
#415 aimed to solve this without contract breaks
The text was updated successfully, but these errors were encountered: