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 race in RetryableTransport #230

Merged
merged 2 commits into from May 8, 2020
Merged

Fix race in RetryableTransport #230

merged 2 commits into from May 8, 2020

Conversation

vbrown608
Copy link
Contributor

There's a race in our RetryableTransport because the submit method writes to an http.Client referenced by a pointer.

uploadFile is called concurrently here, which causes concurrent calls to RetryableTransport.Submit.

go n.uploadFile(ctx, d, file, observer, t, timeout, wg, sem, sharedErr)

I'm a bit uncertain about how the OpenApi runtime works. The RetryableTransport has an http.RoundTripper on it, but the Submit method also also takes an op with it's own Client. I'm not really sure which one is used when. Open to another solution if someone knows this package well.

This PR resolves the race by copying op.Client rather than setting a new Transport on it directly.

It also adds a test to call this method concurrently so that it can be picked up by the race detector. We've been getting panics in Buildbot and I think this may be the reason.

@vbrown608 vbrown608 requested a review from a team as a code owner May 7, 2020 05:25
@netlify
Copy link

netlify bot commented May 7, 2020

Deploy preview for open-api ready!

Built with commit c065ece

https://deploy-preview-230--open-api.netlify.app

@vbrown608 vbrown608 added the type: bug code to address defects in shipped code label May 7, 2020
Copy link
Member

@mraerino mraerino left a comment

Choose a reason for hiding this comment

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

Good catch.

it seems like a hacky solution, but i guess in order to fix it properly the retryable transport would have to be rewritten to change the transport on a different level?

go/porcelain/http/http.go Outdated Show resolved Hide resolved
@vbrown608
Copy link
Contributor Author

it seems like a hacky solution, but i guess in order to fix it properly the retryable transport would have to be rewritten to change the transport on a different level?

Yep!

Copy link
Contributor

@keiko713 keiko713 left a comment

Choose a reason for hiding this comment

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

yay!! no more race! 🏇

@vbrown608 vbrown608 merged commit 2954343 into master May 8, 2020
@vbrown608 vbrown608 deleted the fix-op-client-race branch May 8, 2020 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants