NextJS excessive amount of SSR function invocations

Hi! I’m administering a website https://berachah-church.netlify.app (also set up DNS for just https://berachah.church) and I’m seeing some odd SSR traffic in my function logs (in the ___netlify-handler function).

I’m getting hit with requests every few seconds for routes that do not exist, or routes that are a weird jumble/repetition of valid routes. Here’s a (very small) sampling of just the last minute:

Dec 21, 10:45:54 AM: bf044880 INFO   [GET] /information/lessons/basics/lessons/samples/information/related-activities/information/about/lessons/basics/about/lessons/samples/lessons/lessons/basics/information/about/lessons/samples/selectedlessons.html (SSR)
Dec 21, 10:45:54 AM: bf044880 Duration: 4.57 ms	Memory Usage: 150 MB
Dec 21, 10:45:56 AM: 4be831f5 INFO   [GET] /order/about/about/lessons/basics/lessons/lessons/basics/about/lessons/information/standardsubjectindex.html (SSR)
Dec 21, 10:45:56 AM: 4be831f5 Duration: 5.70 ms	Memory Usage: 150 MB
Dec 21, 10:45:57 AM: dbf193b3 INFO   [GET] /information/lessons/basics/lessons/samples/information/related-activities/information/about/lessons/basics/about/lessons/samples/lessons/basics/about/about/information/lessons/samples/lessons/information/catalog.html (SSR)
Dec 21, 10:45:57 AM: dbf193b3 Duration: 4.68 ms	Memory Usage: 150 MB
Dec 21, 10:46:05 AM: 5b74162d INFO   [GET] /information/lessons/basics/lessons/samples/information/related-activities/information/about/lessons/basics/about/lessons/samples/lessons/lessons/basics/information/about/updates.html (SSR)
Dec 21, 10:46:05 AM: 5b74162d Duration: 5.18 ms	Memory Usage: 150 MB	

Some additional context:

Before switching this site to Netlify, I did have just a static HTML+CSS+JS site hosted on a Windows IIS server. This traffic did not appear while I was developing the site with the generated Netlify URL, only when I made it accessible at it’s current custom domain. Some of the .html resources being requested were names of pages on the old site, but of course were not hosted at those ridiculously long routes.

I am also using next-pwa to serve the site with a service worker, if that has any bearing on this issue :thinking:

I guess I have a few questions on this:

  1. Can I identify where these requests are coming from? I have set up 404 route logging and so am recording legitimate 404s, but none of these weird route requests are being captured by my own logs.
  2. Shouldn’t all 404s fallback to my custom statically generated 404 path? Why is SSR being called at all for these? I only have 7 pages in my site that use SSR.
  3. How can I better handle these so that I don’t run up my function invocations? :sweat_smile:

ETA: my repo isn’t public, but I am running Next.js 12.1.5 and using Supabase for Auth/storage.

Hi @reaganmac ,

I’d be happy to break this down in more detail so you can ask any follow-up questions accordingly.

Next.js currently uses 3 specific functions to work on Netlify. These are the functions:

  1. ___netlify-handler: This function handles the SSR pages, API routes and preview mode functionality.
  2. ___netlify-odb-handler: This one handles ISR routes.
  3. _ipx: This one handles the Next.js Image component.

An important note about the ___netlify-handler function. Because of the way Netlify Redirects work, it also executes for every request that could end up being a 404.

For your site, make sure to check which paths are being treated as server-side, or ISR, etc. This is usually visible here: Netlify App

Now if you go to check your function logs Netlify App, you can see countless requests being made to some of these pages. All of these pages were counted as a function invocation and, for each function invocation, your account was billed according to our pricing for Functions.

To answer your third question, some frameworks that typically use functions can be used in ways that don’t require them to run at browse time, for instance using next export instead of next build will build a “static” Next.js site, when they usually use functions ( Advanced Features: Static HTML Export | Next.js )

Hope this helps!