Skip to content

fix(yurttunnel): avoid reusing pooled bufio.Reader in getResponse - #2787

Open
AruneshDwivedi wants to merge 1 commit into
openyurtio:masterfrom
AruneshDwivedi:fix/yurttunnel-getresponse-race-2774
Open

fix(yurttunnel): avoid reusing pooled bufio.Reader in getResponse#2787
AruneshDwivedi wants to merge 1 commit into
openyurtio:masterfrom
AruneshDwivedi:fix/yurttunnel-getresponse-race-2774

Conversation

@AruneshDwivedi

Copy link
Copy Markdown

Fixes #2774

The getResponse function reads HTTP response headers into a bufio.Reader
and returns the parsed *http.Response whose Body still reads from the
underlying reader. Using a pooled reader and returning it to the pool
via defer before the response body is fully consumed causes a data race
when another goroutine reuses the same pooled reader.

Create a fresh bufio.Reader instead of using the pool to eliminate the
race condition.

The getResponse function reads HTTP response headers into a bufio.Reader
and returns the parsed *http.Response whose Body still reads from the
underlying reader. Using a pooled reader and returning it to the pool
via defer before the response body is fully consumed causes a data race
when another goroutine reuses the same pooled reader.

Create a fresh bufio.Reader instead of using the pool to eliminate the
race condition.

Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
@AruneshDwivedi
AruneshDwivedi requested a review from a team as a code owner August 29, 2026 09:20
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Premature sync.Pool recycling of bufio.Reader in yurttunnel interceptor getResponse causes data race

1 participant