# upstream connection reset by peer while reading response header from upstream

- **ID:** `nginx/upstream-connection-reset-by-peer`
- **Domain:** nginx
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

The upstream server forcibly closes the TCP connection (RST packet) before sending a complete response, often due to application crash or timeout.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| nginx 1.18.0 | active | — | — |
| nginx 1.20.2 | active | — | — |
| nginx 1.22.1 | active | — | — |
| nginx 1.24.0 | active | — | — |
| nginx 1.25.3 | active | — | — |

## Workarounds

1. **Check upstream application logs for crashes or timeouts; fix the application to handle requests gracefully** (85% success)
   ```
   Check upstream application logs for crashes or timeouts; fix the application to handle requests gracefully
   ```
2. **Add retry logic with proxy_next_upstream: proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;** (80% success)
   ```
   Add retry logic with proxy_next_upstream: proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
   ```
3. **Increase upstream keepalive settings to reduce connection churn: keepalive 32;** (60% success)
   ```
   Increase upstream keepalive settings to reduce connection churn: keepalive 32;
   ```

## Dead Ends

- **** — Connection timeout only affects initial handshake, not response reading; RST occurs after connection is established. (80% fail)
- **** — HTTP version change may affect keepalive but doesn't prevent RST from upstream. (70% fail)
- **** — This disables keepalive but upstream may still send RST if it crashes. (65% fail)
