-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
The HTTP request body is never closed, causing a resource leak that will accumulate over time on long-running servers.
Location
http-echo.go:66
body, _ := io.ReadAll(r.Body)Impact
- Severity: HIGH
- Memory leaks on long-running servers
- Connection pool exhaustion
- Degraded performance under load
- Potential server crashes in production
Root Cause
The r.Body is an io.ReadCloser that must be explicitly closed. Failure to close it prevents garbage collection of underlying resources.
Recommended Fix
Add a deferred close immediately after entering the function:
func (h helloWorldhandler) collectRequestInfo(r *http.Request, startTime time.Time) requestInfo {
defer r.Body.Close() // Add this line
// Parse form data
_ = r.ParseForm()
// Read body
body, _ := io.ReadAll(r.Body)
// ... rest of function
}Testing
- Run the server under load with memory profiling
- Verify that memory usage stabilizes after the fix
- Check for resource leaks using
pprof
Priority
Critical - Should be fixed before next release as this affects server stability.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels