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

Never resolving promises #276

Closed
simonguldstrand opened this issue Mar 17, 2020 · 3 comments
Closed

Never resolving promises #276

simonguldstrand opened this issue Mar 17, 2020 · 3 comments

Comments

@simonguldstrand
Copy link

simonguldstrand commented Mar 17, 2020

Hi,

When running:
exports.handler = (event, context) => { return serverlessExpress.proxy(server, event, context) }
My server exits without timeout, but I don't go through my whole event loop, i.e, I don't resolve all promises.

When I run:
exports.handler = (event, context) => { return serverlessExpress.proxy(server, event, context, 'PROMISE').promise }
I execute all my promises, I see all outputs in the right places and go through all operations. But my function times out.

What am I doing wrong?

What parts of the code do you want to see?

index.js


const awsServerlessExpress = require('aws-serverless-express')
const app = require('./main.js')
const server = awsServerlessExpress.createServer(app, null)

exports.handler = (event, context) => {
  return awsServerlessExpress.proxy(server, event, context, 'PROMISE').promise
}

main.js

require('dotenv').config()
var app = require('express')()

const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware')
app.use(awsServerlessExpressMiddleware.eventContext())

app.get('/', (req, res) => {
  res.json(req.apiGateway.event)
})

module.exports = app

I am running node v12.16.1

I launch my test like this:

"scripts": { "test": "run-local-lambda --file index.js --event event.json --timeout 3" },

Thankful for any help, I am so stuck and can't find any help on the internet

@simonguldstrand
Copy link
Author

I also created an entirely fresh project with the files from example. Not waiting for function myFunc () { console.log('hey') } setTimeout(myFunc, 3000) when I run without 'PROMISE'

If I run with 'PROMISE' it times out even if I set 30 seconds when running the local script with run-local-lambda.

@simonguldstrand
Copy link
Author

This problem is identical when running serverless-http package also. It never resolves with promises.

@Poitrin
Copy link

Poitrin commented Aug 20, 2020

Maybe the comments in issue #134 can help you and other developers.

I finally used a callback to avoid the timeout.

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

3 participants