Skip to content

Netlify function can’t resolve api fetch pending state and times out #378

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

Closed
felixhaeberle opened this issue Jun 2, 2021 · 6 comments
Closed
Labels
priority: medium type: bug code to address defects in shipped code

Comments

@felixhaeberle
Copy link

felixhaeberle commented Jun 2, 2021

My netlify site url: https://www.getmelo.io/

Hey, Felix here! I deployed my code to Netlify with a Heroku Postgres DB, but get really slow response time from a very simple subscription form only checking with .findUnique if the email is there and after .create it with the prisma client. From localhost to prod DB it only takes 1-2s, but from Netlify it takes about 10s to write the mail to the database. Where can be the bottleneck?

I did further research and found that Netlify can’t resolve the api fetch and is staying in “pending” state for 10s until it times out, but giving the correct database response and inserts the data.

1:03:46 PM: c5f1b177 INFO   [request] /api
1:03:56 PM: c5f1b177 Duration: 10010.61 ms    Memory Usage: 187 MB    1:03:56 PM: c5f1b177 ERROR  Task timed out after 10.01 seconds1:03:58 PM: 2021-06-01T11:03:58.250Z    undefined    ERROR    (node:8) [DEP0131] DeprecationWarning: The legacy HTTP parser is deprecated.
1:08:27 PM: b267f776 INFO   [request] /api

I’m using @prisma/client@~2.19.0 with prisma@~2.19.0 and nexus-plugin-prisma@~0.33.0

The inserting logic is:

        <ButtonGetStarted         
          onClick={() => {
            setLoading(true);
            setError(false);
            setSubscriptionSuccessful(false);
            createSubscriber({ 
              email, 
            }).then((result) => {
              if (result.data?.createSubscriber?.email) {
                setLoading(false);
                setSubscriptionSuccessful(true);
              } else {
                setLoading(false);
                setError(true);
                console.log(result);
              }
            });
          }}
        >

together with:

    t.nullable.field("createSubscriber", {
      type: "Subscriber",
      args: {
        email: nonNull(stringArg()),
      },
      resolve: async (_, args) => {
        const alreadySubscribed = await prisma.subscriber.findUnique({
          where: {
            email: args.email,
          },
        });

        if (alreadySubscribed) return null;
        
        return await prisma.subscriber.create({
          data: {
            email: args.email
          },
        });
      },
    });

That's my next.config.js

const withPrismaPlugin = require("next-prisma-plugin");

module.exports = withPrismaPlugin({
  target: process.env.NETLIFY ? "experimental-serverless-trace" : undefined
  },
});

Expected behavior
No timeout like in localhost, instant resolving of the db write.

Versions

  • Next.js: 10.0.9

If you're using the CLI to build

  • OS: macOs
  • netlify/cli version:

I'm not using a netlify.toml

@lindsaylevine
Copy link

@felixhaeberle hey felix! can you try something for me? can you npm install --save git://github.com/netlify/netlify-plugin-nextjs#ll/func-template? this should override the default plugin version used. you probably need to clear cache and redeploy site after you commit this change, just because it may have a previous install of the plugin cached. hopefully this is quick enough for you to try out - please let me know if it resolves your issue!

@lindsaylevine
Copy link

Screen Shot 2021-06-02 at 7 04 25 PM

@lindsaylevine lindsaylevine added priority: medium type: bug code to address defects in shipped code labels Jun 2, 2021
@felixhaeberle
Copy link
Author

Thanks! 🎉 It worked. Is this something we can expect to be merged in the Next.js Essentials plugin by default? What do I have to do in order to get this working long-term? Thanks for your advice. 🙏

@lindsaylevine
Copy link

yay thanks so much for trying that out!!! i'm gonna merge that branch now and release a new version of the plugin. i'll circle back here when i'm done :D

@felixhaeberle
Copy link
Author

source

@lindsaylevine
Copy link

@felixhaeberle it's out now as 3.4.0! will close this issue per that release but pls do let us know if you have any other timeout issues!!!

serhalp pushed a commit that referenced this issue Apr 5, 2024
* chore: annotate all skipped tests

* chore: generate test config from JSON file

* chore: generate JSON results

* chore: more annotation

* chore: add more test explanations

* chore: more test config

* chore: more test config

* chore: use reason

---------

Co-authored-by: Michal Piechowiak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

2 participants