Skip to content

[React Router V7] Server timeout after 5 seconds #12467

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
laimonassutkus opened this issue Dec 4, 2024 · 16 comments · Fixed by #12478
Closed

[React Router V7] Server timeout after 5 seconds #12467

laimonassutkus opened this issue Dec 4, 2024 · 16 comments · Fixed by #12478
Labels

Comments

@laimonassutkus
Copy link

laimonassutkus commented Dec 4, 2024

I'm using React Router as a...

framework

Reproduction

Created a freshly new repository. Created minimal example:
https://github.com/laimonassutkus/ReactRouterV7-HttpStreaming

Just run "npm run dev", open the browser and timeout later happens.

How do I increase the timeout beyond 5 seconds ?

Code at a glance

Loader:

export async function loader({}: Route.LoaderArgs) {
    const msgPromise = new Promise((res) =>
        setTimeout(() => res("Hello World!"), 6_000)
    );

    return {msg: msgPromise};
}

Page:

export default function MyComponent({loaderData}: Route.ComponentProps) {
    let {msg} = loaderData;

    return (
        <div>
            <React.Suspense fallback={<div>Loading...</div>}>
                <Await resolve={msg}>
                    {(value) => <h3>{value}</h3>}
                </Await>
            </React.Suspense>
        </div>
    );
}

System Info

Chrome, Mac, dependencies:

    "@react-router/node": "^7.0.2",
    "@react-router/serve": "^7.0.2",
    "isbot": "^5.1.17",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-router": "^7.0.2"

Used Package Manager

npm

Expected Behavior

No timeout happens or at least there is a way to increase it.

Actual Behavior

Always timeout if promise resolves in more that 5 seconds.

@laimonassutkus laimonassutkus changed the title Server timeout after 5 seconds. [React Router V7] Server timeout after 5 seconds Dec 4, 2024
@laimonassutkus
Copy link
Author

laimonassutkus commented Dec 4, 2024

  • By the way, revealing server file with "npx react-router reveal entry.server" and setting "ABORT_DELAY" to, example, 60 seconds did not help either.
  • Building production version did not help also.
  • One thing to note, the response flashes for a brief second before showing server timeout error.
  • Switching to client-side loading (i.e. clientLoader instead of loader) works. But that is not a solution. Server-side loader should not timeout after 5 seconds.

@timdorr
Copy link
Member

timdorr commented Dec 5, 2024

You should export const streamTimeout from your entry.server.tsx file. While not in the main docs, it is in the API reference: https://api.reactrouter.com/v7/interfaces/react_router.ServerEntryModule.html#streamTimeout

Here's the CHANGELOG entry:

- `<RemixServer abortDelay>` is no longer used. Instead, you should `export const streamTimeout` from `entry.server.tsx` and the remix server runtime will use that as the delay to abort the streamed response

@laimonassutkus
Copy link
Author

@timdorr can confirm that it worked. This variable should be part of official documentation because it is very likely for any streamed response to take more than 5 seconds.

@brophdawg11
Copy link
Contributor

FWIW this was in the Single Fetch docs in Remix (https://remix.run/docs/en/main/guides/single-fetch#streaming-timeout) and referenced in the original issue this stemmed from (remix-run/remix#7991 (comment)). I think we need to get some of those long form docs moved over to RR still though so we can use this issue as the docs enhancement 👍

@laimonassutkus
Copy link
Author

@brophdawg11 thank you for the refs! Helpful.

@qinsong77
Copy link

But what if I don't reveal the default entry server file, how can I solve it?

Copy link
Contributor

🤖 Hello there,

We just published version 7.1.0-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@brophdawg11 brophdawg11 added the awaiting release This issue has been fixed and will be released soon label Dec 18, 2024
@brophdawg11
Copy link
Contributor

@qinsong77 #12478 updates the default version of that file to use streamTimeout so that should be resolved for you with the next release.

Copy link
Contributor

🤖 Hello there,

We just published version 7.1.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@qinsong77
Copy link

@qinsong77 #12478 updates the default version of that file to use streamTimeout so that should be resolved for you with the next release.

Thanks for the note, seems I must run react-router reveal

Copy link
Contributor

🤖 Hello there,

We just published version 6.28.2-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@DanielBaulig
Copy link

Is there any way to override this on a per route basis? I would like to use a resource route to feed into Server Sent Events and the requests time out all the time. I don't just want to increase the timeout for the entire server, but just this one route.

Copy link
Contributor

🤖 Hello there,

We just published version 6.28.3-pre-v6.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@brophdawg11
Copy link
Contributor

@DanielBaulig Not at the moment - would you want to write up a proposal discussion here on Github? If it get's enough community interest we would look into implementing it

@brophdawg11 brophdawg11 removed the awaiting release This issue has been fixed and will be released soon label Feb 19, 2025
@seidtgeist
Copy link

@DanielBaulig @brophdawg11 Just my 2 cents:

It's late and I didn't read the docs properly (this also happens in the morning, who am I kidding):

I had wrongly assumed that streamTimeout can "simply" be exported on a per-route basis. This is not the case.

While I'm not nearly deep enough in remix or react-router to know if that would make sense or work: That was my intuition.

@WillSmithTE
Copy link

Wow that took me by surprise.

Imo we should add it to the streaming docs: https://reactrouter.com/how-to/suspense

PR: #13415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
7 participants