serverless: Invoke local keeps hanging after response
This is a Bug Report
Description
-
What went wrong? After invoking a function locally, the console does not exit, it hangs forever until I CTRL+C.
-
What did you expect should have happened? Should exit after response is sent to stdout.
-
What was the config you used?
Here is a sample code using firebase:
const firebase = require('firebase-admin');
async function main(params) {
if (!firebase.apps.length) {
firebase.initializeApp({
credential: firebase.credential.cert(params.FIREBASE_SERVICE_ACCOUNT),
databaseURL: params.FIREBASE_DATABASE_URL
});
}
let user = await firebase.auth().createUser({
email: "deleteme@email.com",
emailVerified: false,
displayName: "Delete Me TEST",
disabled: false,
})
return user
}
Then invoking it like this:
sls invoke local -f my_function
results in the intended function working and logging properly, but the console hangs forever without exiting the action.
Interestingly, if I simulate the same use case using setTimeout() the issue is not reproduced. For example this works and exits correctly:
async function main(params) {
const user = await new Promise( (resolve) => {
setTimeout(()=> {
resolve({status: 'OK'})
}, 2000)
})
return user
}
- What stacktrace or error message from your provider did you see? Nothing. The console shows the expected output (a “user” object in the example provided), but it hangs without closing and any further message.
Similar or dependent issues:
Additional Data
- Serverless Framework Version you’re using: 1.52.0
- Operating System: Ubuntu
- Stack Trace: N/A
- Provider Error messages: N/A
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 14
- Comments: 38 (1 by maintainers)
For me, my issue was a Redis connection that was kept open, so the symptom seems to be that if client connections (of any kind) are not forcefully quit, it will remain open. In my case, I had to
client.quit()to close the connection.Hope this helps someone else diagnose similar issues!
Running 1.64.1 here. I believe this is not a problem with serverless. If using firebase, you have to delete the app once you’re finished:
Maybe you guys could try setting some dummy data as stated on this issue.
Something like:
serverless invoke local -f functioname -l --data {}It seems the only way to really fix this is to stop using sls framework at all and rethinking your backend. Do that and be happy.
Em seg, 21 de set de 2020 18:04, pradeepngupta notifications@github.com escreveu:
this actually solved it for me at the time- guess not anymore
Yeah. It’s back again here too… But I got used to it already. Just do a CTRL+C once the invoke local hangs.
On Wed, Feb 12, 2020, 10:10 Anders Wasen notifications@github.com wrote:
I have an entire project on hold because of this bug, so PLEASE fix it.
This was the issue for me also, I had a connection open to a MYSQL db that needed to be closed.
Been having this issue past few days in both Serverless Offline and the deployed Lambda on AWS. The Firebase database connection keeps the process running, and simply adding the following worked after my firebase usage was done.
firebase.app().delete()I’ve been having the same issue on 1.60.5 and other recent version.
Here’s a solution that’s less than ideal, but still a solution:
yarn add serverless@1.48.0 -Dornpm install serverless@1.48.0 --save-devframeworkVersion: '=1.48.0'This will force your local serverless version to run on version 1.48.0 which appears to be the last version released before the bug was introduced. This solution is less than ideal, but it’s the only thing that’s working for me.
If it’s any hint to the maintainers, I’ve found that problems arise when invoking a local function where I call MongoDB in Nodejs v10.x. If I don’t do this the functions won’t hang. However, in version 1.48.0 and lower, everything works fine no matter what.
On 1.53.0 and having the same issue…
It looks like this might have been introduced in the
1.48.1release