Server side redirects result in a timeout on Vercel
See original GitHub issueWhat 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:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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: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 everyPage
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 beforegetServerSideProps
resulting in some translations getting stuck waiting for resources.thank you for having a look into this!
I’m interested by your findings @balazsorban44, thanks !