# upstream sent invalid chunked transfer encoding while reading response body from upstream

- **ID:** `nginx/upstream-sent-invalid-chunked-transfer-encoding`
- **Domain:** nginx
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

Upstream server sent a malformed chunked response (e.g., missing CRLF, invalid chunk size) that violates HTTP/1.1 chunked transfer encoding rules.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| nginx/1.24.0 | active | — | — |
| nginx/1.22.1 | active | — | — |
| nginx/1.26.0 | active | — | — |

## Workarounds

1. **Fix the upstream application to generate proper chunked encoding (e.g., in Go: ensure http.ResponseWriter uses default chunking correctly, avoid manual chunked writes).** (90% success)
   ```
   Fix the upstream application to generate proper chunked encoding (e.g., in Go: ensure http.ResponseWriter uses default chunking correctly, avoid manual chunked writes).
   ```
2. **Disable chunked transfer encoding in upstream by setting Content-Length header in the response (e.g., in Node.js: res.setHeader('Content-Length', Buffer.byteLength(body)); res.end(body)).** (85% success)
   ```
   Disable chunked transfer encoding in upstream by setting Content-Length header in the response (e.g., in Node.js: res.setHeader('Content-Length', Buffer.byteLength(body)); res.end(body)).
   ```
3. **Use proxy_set_header Connection ''; to force HTTP/1.0 and avoid chunked encoding, then ensure upstream responds with Content-Length.** (75% success)
   ```
   Use proxy_set_header Connection ''; to force HTTP/1.0 and avoid chunked encoding, then ensure upstream responds with Content-Length.
   ```

## Dead Ends

- **** — Timeout does not fix malformed data; the error is structural, not timing-related. (75% fail)
- **** — If upstream expects HTTP/1.1, this may break communication; also, nginx still parses chunked if upstream sends it. (65% fail)
- **** — This directive does not exist in nginx; it is a common misconception. (90% fail)
