Skip to content

[Bug]: __netlify-handler function times out #1174

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
1 of 2 tasks
Shubham510 opened this issue Jan 28, 2022 · 27 comments
Closed
1 of 2 tasks

[Bug]: __netlify-handler function times out #1174

Shubham510 opened this issue Jan 28, 2022 · 27 comments
Labels
type: bug code to address defects in shipped code

Comments

@Shubham510
Copy link

Summary

After upgrading from version 3.9 to 4.2.1, the site builds properly but after when visiting the page, it times out and gets a 502 error from the __netlify-handler function. It gives back the following error -

{"errorMessage":"2022-01-28T15:53:17.566Z dcfe2e2a-53a5-44ef-a864-61fd6b598654 Task timed out after 10.01 seconds"}

The same version of the code was working fine with the version 3.9. The logs for __netlify-handler only show a timeout error and there is no other info which can be used for debugging.

Steps to reproduce

.

A link to a reproduction repository

No response

Plugin version

4.2.1

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

No response

Your netlify.toml file

`netlify.toml`
[build]
    command = "npm run build"
    publish = ".next"

[context.production]
    environment = {NEXT_PUBLIC_API_URL=""}

[context.deploy-preview]
    environment = {NEXT_PUBLIC_API_URL=""}


[[plugins]] 
    package = "netlify-plugin-cypress"

[[plugins]]
package = "@netlify/plugin-nextjs"

[build.environment]
CYPRESS_CACHE_FOLDER = "../node_modules/.CypressBinary"
TERM = "xterm"

Your public/_redirects file

`_redirects`
# Paste content of your `_redirects` file here

Your next.config.js file

`next.config.js`
# Paste content of your `next.config.js` file here. Check there is no private info in there.

Builds logs (or link to your logs)

Build logs
# Paste logs here

Function logs

Function logs
8:09:12 PM 5e752d92 Duration: 10008.16 ms	Memory Usage: 275 MB	Init Duration: 186.18 ms
8:09:12 PM 5e752d92 ERROR  Task timed out after 10.01 seconds
8:09:21 PM 7b5ea894 Duration: 10007.95 ms	Memory Usage: 271 MB	Init Duration: 211.42 ms
8:09:21 PM 7b5ea894 ERROR  Task timed out after 10.01 seconds
8:51:25 PM e17c41f2 Duration: 10008.26 ms	Memory Usage: 271 MB	Init Duration: 229.31 ms
8:51:25 PM e17c41f2 ERROR  Task timed out after 10.01 seconds

.next JSON files

generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.
@Shubham510 Shubham510 added the type: bug code to address defects in shipped code label Jan 28, 2022
@ascorbic
Copy link
Contributor

Hi. Can you share a reproduction repository?

@Shubham510
Copy link
Author

Hi - The repo is private, so I cannot share it. But, I can try to create a sample public repo if needed.

@ascorbic
Copy link
Contributor

If you can that would be great. If you can share your routes-manifest and prerender-manifest that would be great too

@Shubham510
Copy link
Author

I tried reproducing the error in a sample project but it gets deployed properly. The routes-manifest and prerender-manifest does not have much but I have shared them below.

routes-manifest

{
  "version": 3,
  "pages404": true,
  "basePath": "",
  "redirects": [
    {
      "source": "/:path+/",
      "destination": "/:path+",
      "internal": true,
      "statusCode": 308,
      "regex": "^(?:/((?:[^/]+?)(?:/(?:[^/]+?))*))/$"
    }
  ],
  "headers": [],
  "dynamicRoutes": [],
  "dataRoutes": [],
  "rewrites": []
}

prerender-manifest

{
  "version": 3,
  "routes": {},
  "dynamicRoutes": {},
  "preview": {
    "previewModeId": "f1ee063deec7814bfb906",
    "previewModeSigningKey": "055b80021ba0759c99283ac964af2060250cefc35bfb97",
    "previewModeEncryptionKey": "19766ce4c6adf3f6228fd9b50bfe782ac20f219422adbdddf778"
  },
  "notFoundRoutes": []
}

@ascorbic
Copy link
Contributor

To confirm, those are the manifests for the sample project that deployts correctly, or for the private site that fails to deploy?

@Shubham510
Copy link
Author

Shubham510 commented Jan 31, 2022

It is for the one that fails.

@jota jota mentioned this issue Feb 4, 2022
2 tasks
@jota
Copy link

jota commented Feb 8, 2022

I testet a couple of other things:

  • Redeployed the project to a new netlify site, but that did not work either.
  • Then redeployed the very same project to vercel and it works.

Now i'm stuck because the function log is empty apart from the timeout message.

Is there a debug option or something I can turn on to dig deeper?

@tuarrep
Copy link

tuarrep commented Mar 1, 2022

Same problem here with cal.com open source project.

You can test it with the fork that I've successfully deployed to Netlify (just added a .env to prevent build failing) here: https://github.com/Pin-Pon-dev/cal.com

The official guide recommends Vercel and no issues are reported about this problem AFAIK (not tested myself).

@cosimochellini
Copy link

I have the same issue 😢 https://github.com/cosimochellini/aws-share-files

On vercel has no problem

On netlify goes on timeout

@ascorbic
Copy link
Contributor

ascorbic commented Mar 7, 2022

Can anyone who has this issue please share the function logs for ___netlify-odb-handler please

@phillippbertram
Copy link

I also have the same issue 😞 with the latest version v4.2.7.
Unfortunately, there are no logs generated for ___netlify-odb-handler I could provide you 🤷

@cosimochellini
Copy link

@ascorbic

same as @phillippbertram
image
image
image

No logs are shown on the https://app.netlify.com/sites/{{yoursite}}/functions/___netlify-odb-handler section

(lattanabooks) in my case

ps. obviously I run some lambda during this range of time 😢

@cosimochellini
Copy link

@ascorbic update:
with 4.3.0 the behavior is the same,
No logs on netlify logs, same error on api side
{"errorMessage":"2022-01-28T15:53:17.566Z dcfe2e2a-53a5-44ef-a864-61fd6b598654 Task timed out after 10.01 seconds"}

@mkubdev
Copy link

mkubdev commented Mar 28, 2022

Like everyone here, we have the same problem on a private codebase i can't share, with 4.3.0

  • Netlify fail to request Mongodb Atlas and i get a timed out message.

Dev build, the request take 919.62ms :
image
Production build, request take 25ms :
image

  • Vercel is working fine.

And as @cosimochellini and @phillippbertram, no logs in every serveless function instead of the timed out message.

@ascorbic
Copy link
Contributor

It's a bit hard for me to see for sure, but it seems like the common factor for all of these is that each of them is making a request to an external API. I've not been able to reproduce any of the shared sites, because they all require API keys to run.

Does this request take longer than 10 seconds? If so, then the issue is simply that by default Netlify Functions have a 10s timeout. This can be increased for paid accoutns. When running lcoally, how long does the request take?

@tuarrep
Copy link

tuarrep commented Mar 28, 2022

I'm not sure cal.com makes an API call when loading the connected user homepage.

However, it makes DB calls for sure.
As I host my DB on Supabase perhaps we can consider it as an API call?

You can try to deploy my working fork of cal.com https://github.com/Pin-Pon-dev/cal.com
I've successfully deployed it to Netlify (by adding a .env file as the build requires it).

I've tested the same repository locally, using the same Supabase database, it's pretty fast and smooth.
So, I'm fairly sure my database doesn't slow down the request.

@ascorbic
Copy link
Contributor

ascorbic commented Mar 29, 2022

Hi @tuarrep
Thanks. Yes, the calls to Supabase were what I was referring to. I did try your example and it builds but does not run, because the .env expects to find Prisma on localhost:3000, which it obviously won't do when deployed. I of course don't have access to your Supabase db.

It would be really useful if somebody could provide a self-contained reproduction that doesn't require me to create databases on an external service, or setup AWS credentials etc.

@ascorbic
Copy link
Contributor

ascorbic commented Apr 4, 2022

Can everyone who is experiencing this problem please check if they're using Material Icons? In @mkubdev 's reproduction it turned out that it was taking 9 seconds to require a single icon from @mui/icons-material!

If you are using Material icons, please see the usage docs for how to efficiently load them. Otherwise you will be importing all 2000+ icons every time, with serious consequences for performance.

@cosimochellini
Copy link

@ascorbic yes, I've been using these icons! in the late afternoon, I try to import the icons in the correct way and I'll let you know!

@cosimochellini
Copy link

cosimochellini commented Apr 4, 2022

@ascorbic great news! I confirm that importing

import AccessAlarmIcon from '@mui/icons-material/AccessAlarm';

instead of

import { AccessAlarm, ThreeDRotation } from '@mui/icons-material';

It dramatically improves the performance of the API routes 🎉💃.

It's a really strange behavior since the API does not require (in my codebase) any icons.

PS, I have a strong suspicion that the same problem can occur with the @mui/material package

So is waay better to do this

import Button from '@mui/material/Button';

instead of

import { Button } from '@mui/material';

StackOverflow link

@ascorbic
Copy link
Contributor

ascorbic commented Apr 4, 2022

That's great! The reason it happens is because Next loads _app and _document for every request, even API routes. You will probably get even better performance if you use Netlify Functions instead of Next API routes if possible, as they don't have any of the Next overhead, and will just run directly without loading any other runtime.

@Shubham510
Copy link
Author

This issue is resolved for me as well after changing the import. Thanks for the help.

@mkubdev
Copy link

mkubdev commented Apr 5, 2022

I can confirm too that removing @mui/icons-material from our package.json solve the issue.
Thank you @ascorbic !

@tuarrep
Copy link

tuarrep commented Apr 5, 2022

I think cal.com doesn't use @mui/icons-material but I encounter the same errors as OP describes

mattvanvoorst-contentful added a commit to contentful/template-marketing-webapp-nextjs that referenced this issue Dec 14, 2022
- Fixing an issue with mui/material-icons breaking Netlify's deploy opennextjs/opennextjs-netlify#1174 (comment)
- Made some small changes to the image component, making the alt property more intuitive
- Fixed some faulty notFound returns in our slug page
- Hard locked the current Next version
- Updated our Node version to 18
mattvanvoorst-contentful added a commit to contentful/template-marketing-webapp-nextjs that referenced this issue Dec 14, 2022
- Fixing an issue with mui/material-icons breaking Netlify's deploy opennextjs/opennextjs-netlify#1174 (comment)
- Made some small changes to the image component, making the alt property more intuitive
- Fixed some faulty notFound returns in our slug page
- Hard locked the current Next version
- Updated our Node version to 18
mattvanvoorst-contentful added a commit to contentful/template-marketing-webapp-nextjs that referenced this issue Dec 15, 2022
- Fixing an issue with mui/material-icons breaking Netlify's deploy opennextjs/opennextjs-netlify#1174 (comment)
- Made some small changes to the image component, making the alt property more intuitive
- Fixed some faulty notFound returns in our slug page
- Hard locked the current Next version
- Updated our Node version to 18
superdav42 added a commit to unfoldingWord/gateway-translate that referenced this issue Jan 11, 2023
@anthonypecchillo
Copy link

anthonypecchillo commented Aug 16, 2023

Can confirm, solution above worked for me on a hobby tier Vercel deploy that was giving 504 Gateway Timeout errors, even for requests sent to my /health via Postman. Fixed up all of my imports app-wide, much faster now, and working in prod. 😎

After a full day of debugging, reading docs, and consulting ChatGPT, I can't believe this was it.

jarodreyes pushed a commit to jarodreyes/devmarketing that referenced this issue Oct 30, 2023
- Fixing an issue with mui/material-icons breaking Netlify's deploy opennextjs/opennextjs-netlify#1174 (comment)
- Made some small changes to the image component, making the alt property more intuitive
- Fixed some faulty notFound returns in our slug page
- Hard locked the current Next version
- Updated our Node version to 18
@kirtirajsinh
Copy link

on a hobby tier Vercel deploy that was giving 504 Gateway Timeout errors, even for requests sent to my /health via Postman. Fixed up all of my imports app-wide

I'm using shadcn UI and it is using react-icons under the hood. Does it solve for that as well?

@Aleksandr-Pod
Copy link

Aleksandr-Pod commented Nov 19, 2024

Hey people. If I use a mongoose lib shoul I change an import {Schema, model, models} from 'mongoose' with it's 871Kb ?
Should it be like this ?
import Schema from "mongoose/Schema";
import model from "mongoose/model";
import models from "mongoose/models";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

10 participants