Skip to content
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

Getting status 504 when request is aborted during caching and a new request is sent #79

Open
k4rli opened this issue Mar 3, 2023 · 1 comment

Comments

@k4rli
Copy link

k4rli commented Mar 3, 2023

I'm using next-boost with redis cache adapter. It appears that 504 can easily be produced in uncached pages that have getServerSideProps taking more than 1 sec (this probably doesn't matter but for me getServerSideProps can take 5 seconds easily).

Using next-boost request handler in a standard way

// nextRequestHandlerMiddleware.js

const CachedHandler = require("@next-boost/next-boost").default;

const getNextRequestHandler = async (dev) => {
  const args = { dev };

  let handler;
  if (dev) {
    const init = require("./init").default;
    handler = await init(args);
  } else {
    const script = require.resolve("./init");
    const cached = await CachedHandler(
      {
        script,
        args,
      },
      {
        quiet: true,
      },
    );
    handler = cached.handler;
  }
  return handler;
};

module.exports = getNextRequestHandler;
// server.js

...

  const handler = await getNextRequestHandler(IS_DEV);

  server.get("*", handler);

How to reproduce:

# initial request is sent to the page without existing cache and aborted before a response is given with ctrl+c
curl "https://myapp/en/page-without-cache" -v 

# new request is sent right after aborting previous request, response is waited and will have status 504
curl "https://myapp/en/page-without-cache" -v

# final request is sent after 504, response to this will be 200 as the page will be cached at this point
curl "https://myapp/en/page-without-cache" -v
@k4rli
Copy link
Author

k4rli commented Mar 8, 2023

Might have been the same case as "'get /slow-10100'" test, however I discovered that it would be best to have this library cache 308 nextjs redirects (return { redirect: { permanent: true, destination: url }). I included status code (in case of 200 or 308 from render result) in cached data in my fork and it got better.

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

No branches or pull requests

1 participant