I'm encountering a problem with my Next.js 14 App Router application that only happens when it's running on Bun within a Kubernetes cluster. Specifically, I'm seeing errors like 'Invalid response format' and 'TypeError: invalid json response body' for RSC/_rsc requests. The strange part is that Bun works correctly on my local environment and also functions well in AWS ECS. This failure only occurs in Kubernetes, where I'm using NGINX as the ingress. It's worth mentioning that switching to Node immediately resolves the problem. My setup consists of Bun as the server runtime in a Kubernetes cluster with NGINX ingress, and while normal routes and APIs function properly, RSC/Flight responses keep breaking. It seems like there might be an issue with how Bun's HTTP server interacts with RSC chunk streaming behind NGINX in Kubernetes. Is this a known problem, and are there specific ingress settings or Bun configurations I could adjust to fix the RSC responses?
2 Answers
I’ve seen similar issues with Bun in Kubernetes, and it often relates to how NGINX handles traffic. If possible, keep experimenting with different configurations. Sometimes downgrading or upgrading Bun or NGINX can resolve weird incompatibilities.
Bun has some peculiarities when it comes to handling proxy buffers, which can lead to issues like this. One workaround is to use a different proxy that doesn't buffer, such as Traefik, or try disabling buffering with specific NGINX annotations. Here are a few settings you might want to consider trying:
```
nginx.ingress.kubernetes.io/proxy-buffering: "off"
nginx.ingress.kubernetes.io/proxy-request-buffering: "off"
nginx.ingress.kubernetes.io/proxy-body-size: "0"
```

I tried those annotations in my Ingress controller but to no avail. I've found that switching from Bun to Node resolves the issue, but I'm still not clear on why this happens.