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

AWS Lambda timed out #1754

Closed
WellFail opened this issue Mar 3, 2020 · 12 comments
Closed

AWS Lambda timed out #1754

WellFail opened this issue Mar 3, 2020 · 12 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: deployment-platform topic: serverless
Milestone

Comments

@WellFail
Copy link

WellFail commented Mar 3, 2020

Currently, I use prisma2@2.0.0-preview022, nexus@0.12.0-rc.13, nexus-prisma@0.10.0

I deploy the app (with nexus-prisma crud) with Serverless to AWS Lambda and I have some problems.
After executing some query at the deployed endpoint, I couldn't open the graphql playground in the browser because lambda function now is timed out, but all the time while the page tries to open I can make requests to the endpoint with Graphql Playground app and these queries execute fine. After lambda timed out I can reload the page with graphql playground and that will work fine.

This is AWS X-Ray for lambda:
image
In logs only this:
image

@WellFail
Copy link
Author

WellFail commented Mar 4, 2020

This problem only appears when using nexus-prima crud. If I use my custom resolver and add prisma.disconnect(); after prisma operations, then this problem is not observed.

@WellFail
Copy link
Author

WellFail commented Mar 5, 2020

I fixed that problem by graphql-middleware for all queries adding prisma.disconnect() after execution.
It's working, but it is not a good solution I think.

@timsuchanek
Copy link
Contributor

Thanks for reporting @UWellFail! It would be really awesome, if you could have a minimal reproduction repo, so that we can reproduce this!
It highly depends how you call the lambda function. Normally lambda should end the call.

@timsuchanek timsuchanek self-assigned this Mar 5, 2020
@WellFail
Copy link
Author

WellFail commented Mar 5, 2020

@timsuchanek
https://github.com/UWellFail/prisma2--1754

  1. Open the two tabs of graphql-playground
  2. Make any request in one tab
  3. Reload second tab (it will be timed out)

@pantharshit00
Copy link
Contributor

I was unable to reproduce this with the instance that I have deployed: https://v47qk2xs35.execute-api.us-east-1.amazonaws.com/dev/

Also, try this again with the latest version preview023.

@pantharshit00 pantharshit00 added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. labels Mar 6, 2020
@WellFail
Copy link
Author

WellFail commented Mar 6, 2020

@pantharshit00
Copy link
Contributor

Thanks for the video. Indeed I can also reproduce this after I followed the video.

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Mar 6, 2020
@d2kx
Copy link

d2kx commented Mar 9, 2020

Another thing you can probably do is to set

context.callbackWaitsForEmptyEventLoop = false;

for the Lambda handler instead of disconnecting the Prisma client and in the beginning of the handler check if Prisma/whatever the name of your Prisma client instance is already exists, as a warm Lambda runtime container would be able to reuse a previous instance, if the Prisma client instance is created outside of the Lambda handler function.

@janpio
Copy link
Member

janpio commented Mar 17, 2020

Internal Note: First investigation by @timsuchanek at https://prisma-company.slack.com/archives/CUXLS0Z6K/p1584459490008300

@Jolg42
Copy link
Member

Jolg42 commented Mar 19, 2020

I reproduced the timeout with https://github.com/UWellFail/prisma2--1754

I solved the timeout by modifying https://github.com/UWellFail/prisma2--1754/blob/master/src/index.js with

exports.server = (event, context, cb) => {
+  // Set to false to send the response right away when the callback executes, instead of waiting for the Node.js event loop to be empty.
+  context.callbackWaitsForEmptyEventLoop = false;

  return lambda.createHandler({
    cors: {
      origin: '*',
    },
  })(event, context, cb);
};

Can you please try that @UWellFail and confirm it solves your problem?

@WellFail
Copy link
Author

@Jolg42 I try this solution, its solves my problem

@hdngr
Copy link

hdngr commented Mar 29, 2020

This should be in the docs 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: deployment-platform topic: serverless
Projects
None yet
Development

No branches or pull requests

8 participants