Skip to content
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

Invoke local keeps hanging after response #6679

Open
Jonarod opened this issue Sep 12, 2019 · 38 comments
Open

Invoke local keeps hanging after response #6679

Jonarod opened this issue Sep 12, 2019 · 38 comments

Comments

@Jonarod
Copy link

Jonarod commented Sep 12, 2019

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
@martrik
Copy link

martrik commented Sep 17, 2019

I'm having the same issue with version 1.52.0 and an async inside the function.

@paul-ridgway
Copy link

It looks like this might have been introduced in the 1.48.1 release

@martrik
Copy link

martrik commented Oct 1, 2019

Actually, in my case the problem is that I've got a MongoDB connection that should be kept open between executions. However, even when using callbackwaitsforemptyeventloop = false the lambda still hangs.

@paul-ridgway
Copy link

paul-ridgway commented Oct 1, 2019

Ah I see, for me there has been no code change, it "broke" on updating the version so I stepped back to find out when the behaviour appears to have changed...

@martrik
Copy link

martrik commented Oct 1, 2019

Interesting! For me this is a new service that I was creating so I wasn't really sure if the issue originated from my code or serverless'. Anyways, let's see if we can get the attention of any maintainer 😄

@QAnders
Copy link

QAnders commented Oct 3, 2019

On 1.53.0 and having the same issue...

@QAnders
Copy link

QAnders commented Oct 17, 2019

Still there on 1.54.0...
slow-serverless-return

@stellalie
Copy link

Yes, I got the same issue :) - Please fix this.

@selected-pixel-jameson
Copy link

Having the same issue on 1.54.0.

@QAnders
Copy link

QAnders commented Oct 27, 2019

Still hanging on 1.55.1, although it seems to not "freeze" for as long now...

@mstrazzini
Copy link

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

@mstrazzini
Copy link

The setTimeout() trick didn't work for me. Although it doesn't seem to affect deployed functions at all (sls invoke to the deployed functions works fine), so this is not really as urgent as I thought, but it is still annoying.

@selected-pixel-jameson
Copy link

Yes. It is super annoying having to cmd+. every time I run the function. But yes,Just annoying not breaking anything.

@tcastelli
Copy link
Contributor

tcastelli commented Dec 18, 2019

Same problem here :(
I'm trying to use it with serverless-offline-scheduler and this bug makes the plugin hang when calling the functions locally

@KingDarBoja
Copy link

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

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

@jimcamut
Copy link

jimcamut commented Jan 9, 2020

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.

@buildWithSoul
Copy link

buildWithSoul commented Jan 19, 2020

I'm also facing this bug,

nodejs v12.x & serverless core 1.61.2

@mstrazzini
Copy link

mstrazzini commented Jan 19, 2020 via email

@buildWithSoul
Copy link

Just pulled the latest from npm, and it still hangs on git-bash on windows 10 x64

@buildWithSoul
Copy link

buildWithSoul commented Jan 19, 2020

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

@mstrazzini
Copy link

mstrazzini commented Jan 19, 2020 via email

@QAnders
Copy link

QAnders commented Feb 12, 2020

This was fixed but is now back again in the latest release, 1.63.0... :(

@mstrazzini
Copy link

mstrazzini commented Feb 12, 2020 via email

@balassit
Copy link

Facing the same issue on 1.64.0. Please add support for this as it breaks CI/CD builds.

@escar
Copy link

escar commented Mar 10, 2020

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();

@jdchmiel
Copy link

jdchmiel commented May 5, 2020

just checked in on this issue.
serverless invoke local --function adHoc -l --data {}
does not work for 1.67 and I am not using firebase.

@jdchmiel
Copy link

Still here for 1.73. invoking a deployed lambda is fine, just local that hangs. Does anyone have a work around? I need to invoke in a bash a for loop a few hundred times to fake data from an SQS queue.

@jimcamut
Copy link

@jdchmiel I'm using a hack right now to get around this:

  1. yarn add serverless@1.48.0 -D add version 1.48.0 as a dev dependency
  2. In the serverless.yaml file you use to run locally, add frameworkVersion: '=1.48.0' to force it to run 1.48.0.

This will run version 1.48.0 locally for you and things won't hang. This version is the latest before the hanging issue started. I'm also still patiently waiting for a fix, and using this hack to run SLS locally for development purposes, while deploying updated serverless versions to production.

@nmklotas
Copy link

nmklotas commented Aug 7, 2020

having the same issue with:

PS C:\Users\nemok\source\repos\invoices\api> serverless --version                                      
Serverless: DOTENV: Loading environment variables from .env:
Serverless:      - MONGODB_CONNECTION_URL
Serverless:      - iss
Framework Core: 1.78.1
Plugin: 3.7.0
SDK: 2.3.1
Components: 2.34.1
PS C:\Users\nemok\source\repos\invoices\api> 

@chandrakommuri
Copy link

same issue in 1.80.0 as well

@pradeepngupta
Copy link

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:

@mstrazzini
Copy link

mstrazzini commented Sep 21, 2020 via email

@okonon
Copy link

okonon commented Sep 25, 2020

same issue here

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.16.3
     Framework Version:         2.2.0 (local)
     Plugin Version:            4.0.4
     SDK Version:               2.3.2
     Components Version:        3.1.4

@huangweijin
Copy link

Any update? This is blocking me to use. the server-mocha-plugin which hangs after the tests are executed.

@danmoore83
Copy link

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()

@smcelhinney
Copy link

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!

@codebravotech
Copy link

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.

@jespinoza-sp
Copy link

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.

Thanks! I'm using TypeORM and destroying the connection before returning the data solved the issue for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests