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

Asset URLs with old hash 500 when you visit them instead of 404 in production #3900

Closed
1 task done
timteeling opened this issue Feb 26, 2018 · 2 comments
Closed
1 task done

Comments

@timteeling
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

If a user happens to request an old bundle resource with an old hash, the response should 404, not 500.

Current Behavior

I'm currently running a Next.js app at https://www.tenable.com/plugins and I'm getting quite a few 500 errors in my logs after I deploy a new version that has a new hash from the build (I'm using sticky sessions to minimize the disruption, but still see some errors long after the deploy).

Steps to Reproduce (for bugs)

200 -> https://custom-server-koa-wxksegmzhf.now.sh/_next/7c048a193f99703d6180e88866b6e06b/app.js

500 Internal server error -> https://custom-server-koa-wxksegmzhf.now.sh/_next/OLD_HASH_VALUE/app.js

Source code area of interest: https://github.com/zeit/next.js/blob/1aade36f13e03db13d23f86dc52a459f9a29e03d/server/index.js#L467

Context

Just trying to minimize the number of unneeded 500 errors 😄

Appreciate all your work and effort!

Your Environment

Tech Version
next canary
node 8.9
OS macOS, node docker
browser
etc
@rovansteen
Copy link
Contributor

Well actually the status code is a 200. It would be great if it would return a non successful status code. I use Cloudflare to cache all my static assets and right now it caches the '500' one because it thinks it's a 200. I assume these assets are all unique due to their ID so I cache them for a month which has a big chance of breaking my site during rolling deployments.

@timteeling
Copy link
Contributor Author

Think this tweak to handleBuildHash would take care of setting the status correctly in production when the hash doesn't match? Would it be okay if I opened a PR with this?

handleBuildHash (filename, hash, res) {
  if (this.dev) {
    res.setHeader('Cache-Control', 'no-store, must-revalidate')
    return true
  }

  if (hash !== this.buildStats[filename].hash) {
    if (this.dev) {
      throw new Error(`Invalid Build File Hash(${hash}) for chunk: ${filename}`)
    }

    this.send404(res);
  }

  res.setHeader('Cache-Control', 'max-age=31536000, immutable')
  return true
}

timteeling added a commit to timteeling/next.js that referenced this issue Mar 5, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Mar 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants