mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-21 07:42:53 +00:00
fix: add server timeouts to prevent goroutine/memory leak from idle keep-alive connections
Without IdleTimeout, clients holding keep-alive connections open indefinitely caused server-side goroutines (and their ~16KB of buffers) to accumulate linearly until OOM.
This commit is contained in:
@@ -17,8 +17,12 @@ import (
|
||||
|
||||
func Start(cfg *config.Config, r chi.Router) error {
|
||||
server := http.Server{
|
||||
Addr: cfg.BindAddress,
|
||||
Handler: r,
|
||||
Addr: cfg.BindAddress,
|
||||
Handler: r,
|
||||
ReadHeaderTimeout: 10 * time.Second, // Prevents slowloris attacks (connections held open without sending headers).
|
||||
IdleTimeout: 90 * time.Second, // Reclaims idle keep-alive connections; without this, goroutines and buffers leak indefinitely.
|
||||
MaxHeaderBytes: 1 << 16, // 64KB
|
||||
// ReadTimeout/WriteTimeout intentionally omitted - a reverse proxy must support slow transfers.
|
||||
}
|
||||
|
||||
serverCtx, serverStopCtx := context.WithCancel(context.Background())
|
||||
|
||||
Reference in New Issue
Block a user