question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server side redirects result in a timeout on Vercel

See original GitHub issue

What version of Next.js are you using?

12.0.4

What version of Node.js are you using?

16.13.1

What browser are you using?

chromium

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

Server side Redirects don’t work when deployed on vercel. Result in

504: GATEWAY_TIMEOUT
Code: FUNCTION_INVOCATION_TIMEOUT

Expected Behavior

redirects should not exceed timeout limits.

To Reproduce

// pages/[...redirectAll].tsx
import { FunctionComponent } from "react";
import { GetServerSideProps } from "next";

const RedirectAll: FunctionComponent = () => <></>;

export const getServerSideProps: GetServerSideProps = async () => ({
  redirect: {
    permanent: false,
    destination: "/",
  },
});

export default RedirectAll;

deployed here:

https://widu-webapp.vercel.app/potato

results in a

504: GATEWAY_TIMEOUT
Code: FUNCTION_INVOCATION_TIMEOUT

works fine locally, and on AWS serverless.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
PupoSDCcommented, Dec 25, 2021

I was able to fix this issue. To be honest, i dont fully understand what happens under the hood, but I have fairly good gut feeling.

Basically, the problem revolves around next-18next, combined with the way my app was setup. My app used to look like this:

// _app.tsx
const App = ({
  Component,
  emotionCache = clientSideEmotionCache,
  pageProps,
  session = null,
}: CustomAppProps) => (
  <StrictMode>
       </BunchOfProviders>
            <PageHeaderThatUsedTranslations />
            <Component {...pageProps} />
        </BunchOfProviders>
  </StrictMode>
);

so when we hit a redirect page there seems to be some translation happening. In fact, with this setup, no server side page works at all. I seem to be hitting the same problem as this guy: https://github.com/vercel/next.js/discussions/32686

I tried a lot of intermediate solutions, like adding the translation setup on my redirect page but nothing worked. In the end the only thing that worked was moving away the <PageHeaderThatUsedTranslations /> to be included in every Page so that translations are not needed unless you ask for it.

I was a bit of a painful experience since there are no logs on Vercel side, and this is not reproducible locally. My wild guess is that on vercel the _app.tsx code gets run before getServerSideProps resulting in some translations getting stuck waiting for resources.

thank you for having a look into this!

1reaction
tooppaaacommented, Dec 23, 2021

I’m interested by your findings @balazsorban44, thanks !

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I increase the limit of redirects or use dynamic ...
In this article, we describe methods to redirect a path to another location by using Next.js and Vercel features. Using Serverless Functions or...
Read more >
What can I do about Vercel Serverless Functions timing out?
Check the Response​​ Your Serverless Functions need to return an HTTP Response even if it's a response that indicates an error. If a...
Read more >
Limits – Vercel Docs
For Teams, the execution timeout is 60 seconds (Pro plan) or 900 seconds (Enterprise plan). For more information, see the Execution Timeout section....
Read more >
Serverless Functions – Vercel Docs
The timeout is determined by the "Serverless Function Execution Timeout (Seconds)" limit, which is based on the plan that the Personal Account, or...
Read more >
How do I resolve "err_too_many_redirects" when using a ...
Vercel identifies an unprotected request to http://example.com and sends a 308 status code redirect to https://example.com . Cloudflare will forward the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found