I should be able to run a nextjs app on multiple server replicas without errors occurring.
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.
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.
| Tech | Version |
|---------|---------|
| next | 4.1.4 |
| node | 8 |
| OS | CoreOS |
| browser | Chrome/Firefox |
| etc | |
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.
Most helpful comment
Turns out I needed to also override
.next/BUILD_IDto have the same consistent value.