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

wait for done before writing to shared resp body #532

Merged
merged 1 commit into from
Jan 28, 2019

Conversation

ldelossa
Copy link

@ldelossa ldelossa commented Jan 27, 2019

This PR fixes what seems to be a data race condition. Previously if the caller of this Do() canceled the context, or the provided context has timed out the select statement would enter that branch and then close the response body. This could potentially occur concurrently with launched go routine on line 115. My solution simply moves the receive on the done channel before the close of the resp body.

May want to consider whether we check context in the go routine launched on line 115 before reading the body as a good measure of "don't do work you don't need too". I'll wait for initial comments on this PR to make sure my logic is correct.

fixes #531

Signed-off-by: Louis Delossantos <ldelossa.ld@gmail.com>
@beorn7
Copy link
Member

beorn7 commented Jan 27, 2019

The pre Go 1.11 test errors happen because we rolled back the formatting change in prometheus/common.

I'll revert our changes here in prometheus/client_golang, too, at my next convenience. For now, just look at the Go 1.11.x tests, which are fine.

@beorn7
Copy link
Member

beorn7 commented Jan 27, 2019

After #533 is merged, the tests should pass.

@krasi-georgiev krasi-georgiev merged commit 12af604 into prometheus:master Jan 28, 2019
@krasi-georgiev
Copy link
Contributor

Thanks!

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.

DataRace detected with concurrent use of client
3 participants