Skip to content

Commit

Permalink
Ensure failed request buffers are cleaned up
Browse files Browse the repository at this point in the history
When using `NewBufferedReadCloser`, it's normally the client's
responsibility to `Close()` the returned buffer. However, if there's an
error when initially populating the buffer, we don't return the failed
buffer to the client, and we weren't closing it ourselves. This leads to
stale buffers being left behind.

Instead, if we can't return a properly populated buffer, we should close
and discard it before returning nil.
  • Loading branch information
kevinmcconnell committed Sep 23, 2024
1 parent 68889d3 commit 556aa40
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions internal/server/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewBufferedReadCloser(r io.ReadCloser, maxBytes, maxMemBytes int64) (io.Rea

_, err := io.Copy(buf, r)
if err != nil {
buf.Close()
return nil, err
}

Expand Down

0 comments on commit 556aa40

Please sign in to comment.