# http: Server.Shutdown: context deadline exceeded

- **ID:** `go/http-server-shutdown-error`
- **Domain:** go
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

During graceful shutdown, the server did not finish processing active requests within the given context deadline.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.16 | active | — | — |
| 1.20 | active | — | — |

## Workarounds

1. **** (85% success)
   ```
   Set a reasonable timeout and handle error: ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second); defer cancel(); if err := srv.Shutdown(ctx); err != nil { log.Fatal(err) }
   ```
2. **** (90% success)
   ```
   Track active connections and wait for them before calling Shutdown: use sync.WaitGroup to wait for handlers to finish.
   ```

## Dead Ends

- **** — Delays shutdown indefinitely and may not solve if requests hang forever. (60% fail)
- **** — Loses active connections and may corrupt data. (80% fail)
