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

Add InitWithClient and deprecate InitClient because we don't want to copy Client's field sync.RWMutex by value #273

Merged
merged 9 commits into from
Jun 5, 2019

Conversation

mandyh2018
Copy link
Contributor

Init proxy client using pointer because we don't want to copy its filed sync.RWMutex by value.

@hfwang
Copy link
Contributor

hfwang commented May 2, 2019

I think this may not be allowed actually since it changes the API surface...

@mandyh2018
Copy link
Contributor Author

hmm, I can also add a new API.

@kurtisvg kurtisvg requested a review from broady May 6, 2019 16:28
@kurtisvg kurtisvg added Status: Review Needed type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels May 6, 2019
@broady
Copy link
Contributor

broady commented May 6, 2019

Can you tell us about the motivation behind this change? Is there a bug?

@Carrotman42
Copy link
Contributor

Copying a sync.RWMutex is not generally safe, although I think copying an unused (i.e. zero-value) RWMutex can't be noticed by the internal code used to detect this copying. In any case this was definitely an oversight when I wrote this API and the API should be either changed or deprecated/deleted-eventually.

@kurtisvg
Copy link
Contributor

kurtisvg commented May 7, 2019

@broady and I discussed this today and the conclusion was that we should defiantly make this change, but play it safe and create a new function and deprecate the old one.

@mandyh2018
Copy link
Contributor Author

@kurtisvg Thanks! Is it part of your plan? Or I will do it later. :-)

@kurtisvg
Copy link
Contributor

kurtisvg commented May 8, 2019

@mandyh2018 If you would like to make the change you are welcome to, otherwise I will update this PR sometime before the next release.

@broady broady closed this Jun 4, 2019
@broady broady reopened this Jun 4, 2019
@mandyh2018
Copy link
Contributor Author

broady@ are we okay with changing the existing API? I thought we want to add a new one instead.

@mandyh2018
Copy link
Contributor Author

kurtisvg@ Are you working on this? If not, I will add a new API this week. :-)

@kurtisvg
Copy link
Contributor

kurtisvg commented Jun 4, 2019

My plan is to just add a new function (likely InitWithClient) and mark the old one with a deprecated warning. I'm hoping to do it sometime this week, but please feel free to do it sooner if you have time :)

@mandyh2018
Copy link
Contributor Author

Let me work on this then. I have some time today and tomorrow. :-) So I just close this pull request and send a new one? kurtisvg@

@kurtisvg
Copy link
Contributor

kurtisvg commented Jun 4, 2019

You can just update this PR with the changes

@mandyh2018
Copy link
Contributor Author

I updated this PR, please let me know if any comment. Thanks!

@mandyh2018 mandyh2018 changed the title Init proxy client using pointer because we don't want to copy its filed sync.RWMutex by value Init proxy client using pointer because we don't want to copy its field sync.RWMutex by value Jun 4, 2019
@mandyh2018 mandyh2018 changed the title Init proxy client using pointer because we don't want to copy its field sync.RWMutex by value Add InitWithClient and deprecate InitClient because we don't want to copy Client's field sync.RWMutex by value Jun 4, 2019
@@ -80,12 +81,22 @@ func Init(auth *http.Client, connset *ConnSet, dialer Dialer) {

// InitClient is similar to Init, but allows you to specify the Client
// directly.

// Deprecated: Client contains sync.RWMutex, which should not be copied by value.
Copy link
Contributor

Choose a reason for hiding this comment

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

just "Deprecated: Use InitWithClient instead." i think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thx!

Sync with the latest change# Please enter a commit message to explain why this merge is necessary,
@mandyh2018
Copy link
Contributor Author

Thank you! I will wait until I become the authorized user?

@mandyh2018
Copy link
Contributor Author

I can see the warning:
Merging is blocked
The base branch restricts merging to authorized users.
You’re not authorized to merge this pull request.

@broady broady merged commit 1de96dc into GoogleCloudPlatform:master Jun 5, 2019
@broady
Copy link
Contributor

broady commented Jun 5, 2019

Thanks! Merged.

@mandyh2018
Copy link
Contributor Author

Thank you!

@kurtisvg kurtisvg mentioned this pull request Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants