Skip to content

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

Closed
@felixhaeberle

Description

@felixhaeberle

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions