Next.js: "An unexpected error has occurred" on replicated server

Created on 16 Nov 2017  路  4Comments  路  Source: vercel/next.js

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

Expected Behavior



I should be able to run a nextjs app on multiple server replicas without errors occurring.

Current Behavior



Trying to run next 4.1.4 in a kubernetes cluster and about half of the requests to the server result in "An unexpected error has occurred." If the request is made client-side, the only error in the console is 500 - Internal Server Error. undefined. There is no server log with more error details.

This does not appear to be happening with a 3.x app run in a similar context.

Steps to Reproduce (for bugs)


  1. Create next.js 4 app
  2. Run in kubernetes cluster
  3. Load page repeatedly

Context



I've already implemented the build-stats hack here https://github.com/zeit/next.js/issues/2978#issuecomment-334849384 to have consistent build ids across the replicas. That resolved that set of errors but now stuck with undebuggable errors.

ETA: This appears to still be build id related. The error that's thrown has buildIdMismatched: true even through both replicas have identical .next/build-stats.json files.

Your Environment


| Tech | Version |
|---------|---------|
| next | 4.1.4 |
| node | 8 |
| OS | CoreOS |
| browser | Chrome/Firefox |
| etc | |

Most helpful comment

Turns out I needed to also override .next/BUILD_ID to have the same consistent value.

All 4 comments

Turns out I needed to also override .next/BUILD_ID to have the same consistent value.

@sethsamuel , I met the same issue here. But What to do when process a rolling update. The new pods and old pods have different BUILD_IDS.

Without sticky requests I think it's impossible to avoid 500s during a rolling update. It would help if next fell back to server side rendering on mismatched build ids, rather than 500ing, but not sure how hard that would be to implement.

The only way I found is use CDN to cache static files. CDN service like cloudflare knows how to handle two version of the same file.This approach is not perfect, but can reduce many 500 errors.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jesselee34 picture jesselee34  路  3Comments

timneutkens picture timneutkens  路  3Comments

wagerfield picture wagerfield  路  3Comments

renatorib picture renatorib  路  3Comments

flybayer picture flybayer  路  3Comments