The Quick Answer
The “stream disconnected before transport network error decoding response body” usually occurs when an HTTP/2 or gRPC connection drops unexpectedly while data is still being transmitted. To fix it instantly:
1. Increase server timeouts (e.g., Nginx `keepalive_timeout` or Node.js `server.keepAliveTimeout`).
2. Ensure proxy timeouts are greater than your application timeouts.
3. Update your fetch API or Node.js version, as older implementations of `undici` have known HTTP/2 stream bugs.
If you’re building modern web applications using Node.js, Next.js, or gRPC architectures, encountering a sudden application crash or failed fetch request is frustrating. One of the most cryptic messages developers face today is the notorious stream disconnected before transport network error decoding response body.
This comprehensive guide breaks down exactly why this error triggers, how to diagnose it in your specific environment, and the exact steps to implement a permanent fix.
What Causes the Stream Disconnection Error?
At its core, this error is a symptom of a severed HTTP/2 or TCP connection. The client made a request, the server started sending the response body, but the connection was abruptly killed before the transmission completed. The local environment fails to decode the truncated payload, throwing the error.
Also Read : Canva Server Down Today?
Here are the primary culprits behind this disruption:
- Misconfigured Timeouts: A reverse proxy (like Nginx or Cloudflare) has a shorter idle timeout than your backend application.
- Node.js Native Fetch Bugs: Early versions of Node 18 and 20 utilizing the native
fetchAPI (powered by Undici) had documented bugs handling HTTP/2 session closures. - Payload Size Limits: The response body exceeds the buffer limits of your API gateway.
- Premature Process Termination: Serverless functions (like AWS Lambda or Vercel edge functions) timing out while streaming the response.
Step-by-Step Troubleshooting Guide
To effectively optimize for resolution, follow this diagnostic matrix. (If you want to read more about optimizing your server configurations, check out our guide on Node.js backend best practices).
| Environment | Common Root Cause | Recommended Fix |
|---|---|---|
| Node.js (v18+) | Native fetch() bug with Undici HTTP/2. |
Upgrade to latest Node LTS or switch to axios / node-fetch. |
| Next.js / Vercel | Serverless function timeout during SSR/SSG. | Increase function maxDuration in vercel.json. |
| Nginx Proxy | proxy_read_timeout is too low for the stream. |
Increase timeout values to 60s or 120s in nginx.conf. |
Fix 1: Adjusting Keep-Alive Timeouts
If you are running Node.js behind a Load Balancer, your Node server’s Keep-Alive timeout must be greater than the Load Balancer’s idle timeout. Otherwise, Node closes the connection while the LB thinks it’s still active, resulting in the decode error.
// Express.js Example Fix
const server = app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
// Set Node keep-alive to 65 seconds
server.keepAliveTimeout = 65000;
// Ensure headers timeout is larger than keepAliveTimeout
server.headersTimeout = 66000;
Fix 2: Bypassing the Native Fetch Bug
The Node.js community has heavily documented this issue on the Undici GitHub repository. If you cannot update your Node version immediately, falling back to HTTP/1.1 or using an alternative library resolves it.
If you are struggling with deeper networking issues, don’t hesitate to contact our expert support team for infrastructure audits.
TL;DR Summary
- The Problem: A network connection drops before a client can finish downloading a response, causing a parsing crash.
- Why it happens: Mismatched timeouts between servers and proxies, serverless function limits, or HTTP/2 Node.js bugs.
- The Solution: Ensure your backend (Node.js/Python/Go) timeout settings are slightly longer than your frontend proxy (Nginx/Cloudflare) settings. Upgrade to the latest stable runtime to patch known API bugs.
About the Author
Senior Backend Engineering Team – Written by developers with over 10 years of experience resolving high-availability network issues. Last updated: July 2, 2026.
Sources: Node.js Official Documentation, Internal QA Testing.
1 thought on “Fix “Stream Disconnected Before Transport Network Error Decoding Response Body” Fast”