Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buffer-pooling ingester client #5830

Merged
merged 3 commits into from
Aug 24, 2023
Merged

Conversation

pstibrany
Copy link
Member

@pstibrany pstibrany commented Aug 24, 2023

What this PR does

This PR fixes data race caused by using buffer-pooling ingester client, originally introduced in #5195. Before this PR the client would always return buffers to the pool. However in case of context cancellations buffers could still be enqueued for sending inside gRPC client, and returning them back to pool would cause data race.

Checklist

  • Tests updated
  • [na] Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
@pstibrany pstibrany requested a review from a team as a code owner August 24, 2023 12:46
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I could see that go test -race detects raciness when reverting your fix.

pkg/ingester/client/buffering_client_test.go Outdated Show resolved Hide resolved
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
@pstibrany pstibrany merged commit 1513305 into main Aug 24, 2023
27 checks passed
@pstibrany pstibrany deleted the fix-buffer-pooling-ingester-client branch August 24, 2023 13:45
// return them to the pool.
wr.ReturnBuffersToPool()
}
return resp, err
Copy link
Member

@jhalterman jhalterman Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do buffers ever get returned to the pool in the case of an error? If not, is that a problem?

Copy link
Member Author

@pstibrany pstibrany Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they don't. When this optimization (buffering client) is disabled, then there's no buffer reuse at all, so overall this is still an improvement.

Copy link
Member

@jhalterman jhalterman Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If enough buffers are not returned to the pool, could it eventually become empty? Maybe instead of returning a buffer to the pool on error, you can inform the pool that it has an empty slot?

Copy link
Member Author

@pstibrany pstibrany Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pool also starts empty. If an existing buffer cannot be retrieved from the pool, new buffer is allocated, and then put into the pool when not used anymore.

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.

3 participants