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)

Most upvoted comments

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:

firebase.app().delete();

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:

Any update on this issue? I am facing the same issue with: Your Environment Information --------------------------- Operating System: win32 Node Version: 12.18.1 Framework Version: 2.1.1 Plugin Version: 4.0.4 SDK Version: 2.3.2 Components Version: 3.1.3

Even the expected output is not coming: $ sls invoke local -f hello Serverless: Running “serverless” installed locally (in service node_modules) Serverless: DOTENV: Loading environment variables from .env:

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/serverless/serverless/issues/6679#issuecomment-696375684, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZOCQ4PEBZLFERAMFBB6RTSG65WJANCNFSM4IWKKNQA .

Maybe you guys could try setting some dummy data as stated on this issue.

Something like: serverless invoke local -f functioname -l --data {}

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:

This was fixed but is now back again in the latest release, 1.63.0… 😦

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/serverless/serverless/issues/6679?email_source=notifications&email_token=AFZOCQ6RHBKJBVE3X5OWA33RCPYLNA5CNFSM4IWKKNQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELQWRFY#issuecomment-585197719, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZOCQ7IFNMYQGYMHZ2EW5LRCPYLNANCNFSM4IWKKNQA .

I have an entire project on hold because of this bug, so PLEASE fix it.

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!

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:

  1. yarn add serverless@1.48.0 -D or npm install serverless@1.48.0 --save-dev
  2. In your serverless.yml file add frameworkVersion: '=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.1 release