Skip to content

Vercel 504 on all API routes #15280

Closed
Closed

Description

@saiichihashimoto

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

8.33.0-8.54.0

Framework Version

8.33.0-8.54.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

No matter what I do, my endpoints are all hanging with a vercel 504 error. Sometimes they come through, but rarely. It's only on /api/* routes as all my pages load, though I'm not doing any get* methods on them. When I completely remove Sentry from my codebase, everything is extremely fast and there are no errors whatsoever. It works running next dev locally, but only fails like this when deployed to vercel. All my environment variables are fine.

Steps to Reproduce

No matter what I do, my endpoints are all hanging with a vercel 504 error. Sometimes they come through, but rarely. It's only on /api/* routes as all my pages load, though I'm not doing any get* methods on them.

Expected Result

Every API shouldn't be returning a 504 error.

Actual Result

Every API shouldn't be returning a 504 error.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Feb 3, 2025
  2. changed the title [-]Vercel 504'[/-] [+]Vercel 504 on all API routes[/+] on Feb 3, 2025
  3. s1gr1d commented on Feb 4, 2025

    @s1gr1d
    Member

    Hello, thanks for writing in. Can you please provide a minimal reproduction example?

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Feb 4, 2025
  5. saiichihashimoto commented on Feb 5, 2025

    @saiichihashimoto
    Author

    Sorry, I had to rip out my Sentry integration to have a working site, so a repro would be a lift. I just followed the docs for integration Sentry/Next/Sentry with the tunneling and then had a /api/health-error that all it would do is throw an error. Instead of being a 500, it would hang for 10s+ and give a 504. All my other api routes were hanging with a 504 (including some successful ones). Even a /api/health endpoint that just returned a json blob would take a very long time. Once I took out Sentry, all these problems vanished.

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Feb 5, 2025
  7. chargome commented on Feb 5, 2025

    @chargome
    Member

    @saiichihashimoto could you maybe share your next config file in the state that caused the issue?

  8. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Feb 5, 2025
  9. saiichihashimoto commented on Feb 5, 2025

    @saiichihashimoto
    Author
    const { withSentryConfig: withSentryConfigRaw } = require("@sentry/nextjs");
    
    const { flow } = require("lodash/fp");
    
    const withBundleAnalyzer = require("@next/bundle-analyzer");
    
    const withSentryConfig =
      (
        /** @type {import("@sentry/nextjs").SentryBuildOptions | undefined} */ sentryBuildOptions
      ) =>
      (/** @type {import('next').NextConfig} */ config) =>
        withSentryConfigRaw(config, sentryBuildOptions);
    
    /**
     * @type {import('next').NextConfig}
     */
    const config = {
      transpilePackages: ["@REDACT/*"],
      pageExtensions: ["page.tsx", "page.ts", "page.jsx", "page.js"],
      productionBrowserSourceMaps: true,
      eslint: {
        ignoreDuringBuilds: true,
      },
      experimental: {
        instrumentationHook: true,
        swcPlugins: [
          [
            "next-superjson-plugin",
            {
              excluded: [],
            },
          ],
        ],
      },
      headers: async () => [
        {
          source: "/assets/:asset*",
          headers: [
            {
              key: "cache-control",
              value: "public, immutable, max-age=31536000",
            },
          ],
        },
      ],
      images: {
        remotePatterns: [
          {
            protocol: "https",
            hostname: "lh3.googleusercontent.com",
            port: "",
          },
        ],
      },
    };
    
    /**
     * @type {import('next').NextConfig}
     */
    module.exports = flow(
      withSentryConfig({
        automaticVercelMonitors: true,
        debug: Boolean(process.env.CI),
        disableLogger: true,
        hideSourceMaps: true,
        org: REDACT,
        project: REDACT,
        silent: !process.env.CI,
        tunnelRoute: "/monitoring",
        widenClientFileUpload: true,
        reactComponentAnnotation: {
          enabled: true,
        },
      }),
      withBundleAnalyzer({
        enabled: process.env.ANALYZE === "true",
      })
    )(config);
  10. 10 remaining items

  11. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Feb 7, 2025
  12. chargome commented on Feb 7, 2025

    @chargome
    Member

    Another thing: found an old issue with next-superjson-plugin – this might also be the culprit.

  13. saiichihashimoto commented on Feb 12, 2025

    @saiichihashimoto
    Author

    I am just wondering if the flow call is correct here.

    It should resemble this, am I right?

    withSentryConfig(
    withBundleAnalyzer({ /* Next.js config /}),
    { /
    Sentry options */ }
    )
    I think this would be the correct way of doing this:

    module.exports = flow(
    withBundleAnalyzer({
    enabled: process.env.ANALYZE === "true",
    }),
    config => withSentryConfig(config, {
    /* Sentry options */
    })
    )(config);
    Maybe try to create the config without currying it. withSentryConfig is not an unary function and needs the Next.js config and the Sentry options, while withBundleAnalyzer is a unary function. But in your code snippet, you were adding them to flow in a similar way.

    See how I'm importing it as withSentryConfigRaw and redefining withSentryConfig to essentially be exactly what you're saying. If you were right, then I'd be having a lot more issues, ie all the other props wouldn't be doing their jobs, but they are. Regardless, I had tried what you're suggesting to no effect.

  14. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Feb 12, 2025
  15. saiichihashimoto commented on Feb 12, 2025

    @saiichihashimoto
    Author

    Another thing: found an old issue with next-superjson-plugin – this might also be the culprit.

    It MIGHT be, but none of my errors resemble the errors I'm seeing here, so I'm not inclined to believe that's what's happening.

  16. lforst commented on Feb 13, 2025

    @lforst
    Contributor

    My guess is that you have some other package that is not a nice citizen. In those cases we would need a repro cause otherwise it becomes a guessing game. If you can share relevant code that would be great, otherwise there's not much we can do right now. :/

  17. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Feb 13, 2025
  18. moved this to Waiting for: Community in GitHub Issues with 👀 3on Mar 4, 2025
  19. saiichihashimoto commented on Mar 10, 2025

    @saiichihashimoto
    Author

    It does seem like it was another issue. I couldn't find where it was, but it seemed to be triggered only when sentry was also involved 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions