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

local function hangs #79

Open
srchulo opened this issue Jun 13, 2020 · 4 comments
Open

local function hangs #79

srchulo opened this issue Jun 13, 2020 · 4 comments

Comments

@srchulo
Copy link

srchulo commented Jun 13, 2020

When I follow this example:

// Require and initialize outside of your main handler
const mysql = require('serverless-mysql')({
  config: {
    host     : process.env.ENDPOINT,
    database : process.env.DATABASE,
    user     : process.env.USERNAME,
    password : process.env.PASSWORD
  }
})
 
// Main handler function
exports.handler = async (event, context) => {
  // Run your query
  let results = await mysql.query('SELECT * FROM table')
 
  // Run clean up function
  await mysql.end()
 
  // Return the results
  return results
}

By invoking my function locally:

sls invoke local -f myFunction

results gets returned by the handler, but then it just hangs forever and the sls command never returns (command prompt doesn't come back). I need to hit ctrl c to end it.

@srchulo
Copy link
Author

srchulo commented Jun 14, 2020

I've tried setting:

context.callbackWaitsForEmptyEventLoop = false

And it still doesn't work, but I don't think that I should need to set that since I'm using an async function?

@srchulo
Copy link
Author

srchulo commented Jun 14, 2020

If I do mysql.quit() instead of end, my function doesn't hang, but obviously that's not great :)

@srchulo
Copy link
Author

srchulo commented Jun 14, 2020

From this link, it looks like maybe this is expected behavior:

serverless/serverless#470 (comment)

And maybe it should be covered in the documentation?

@davidrhoderick
Copy link

@srchulo did you get this all sorted out? I'm trying to get serverless-localstack working with serverless-mysql and I just can't get it to work. I believe that issue you reference provides some insight but I just can't develop with this plugin locally as it doesn't work unless just invoking functions (and even still, I'd have to change the code for staging/production).

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

No branches or pull requests

2 participants