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

Update ServiceClient so ProductInfoHeaderValues are not duplicated and are merged without error #4095

Closed
wants to merge 5 commits into from

Conversation

EricDahlvang
Copy link

Description


This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

SDK Generation Guidelines

  • If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
  • The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code.
  • The *.csproj and AssemblyInfo.cs files have been updated with the new version of the SDK.

Eric Dahlvang added 2 commits February 26, 2018 14:37
Check that .Product is not null during merge of ProductInfoHeaderValues.

Do not add Product to UserAgent if already present.

Dispose of root handler if created.
Add tests to ensure ProductInfoHeaderValues are not added to UserAgent twice, and those constructed with 'comment' constructor are ignored during merging.
@azuresdkci
Copy link
Contributor

Can one of the admins verify this patch?

2 similar comments
@azuresdkci
Copy link
Contributor

Can one of the admins verify this patch?

@azuresdkci
Copy link
Contributor

Can one of the admins verify this patch?

@EricDahlvang
Copy link
Author

ref: #4086


}

if (_disposeRootHandler)
Copy link
Member

Choose a reason for hiding this comment

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

@EricDahlvang let's just call Dispose on the set the Handlers that are part of ServiceClient. I don't think it's required to have a flag to track it.

Copy link
Author

Choose a reason for hiding this comment

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

If the ServiceClient did not create the handler, then it should not dispose it. This addition only disposes it if it was internally created.

issue ref: #3712

Copy link
Member

Choose a reason for hiding this comment

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

@EricDahlvang Maybe I am not able to understand your scenario.
Can you tell me a scenario where someone will initialize Service client and would like to use it's RootHandler after disposing the service client.

Copy link
Author

Choose a reason for hiding this comment

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

Anyone who uses this constructor:

https://github.com/EricDahlvang/azure-sdk-for-net/blob/e13313279e108e350289dc7373414bcac4e4602a/src/SdkCommon/ClientRuntime/ClientRuntime/ServiceClient.cs#L288

        protected ServiceClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers)
        {
            InitializeHttpClient(rootHandler, handlers);
        }

(I don't personally use that constructor, but I saw that this is an issue ... so included it in this PR)

Copy link
Author

Choose a reason for hiding this comment

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

It looks like I missed something. Constructors on lines 250 and 258 also create the RootHandler, and in those cases it should be disposed.

Copy link

Choose a reason for hiding this comment

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

@EricDahlvang is this still in discussion, I found some issue related.I agree with you.It's not thread safe when set the user agent to the http client header.This will lead some critical issue when using http client

Copy link
Author

Choose a reason for hiding this comment

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

@mjaow I have no idea if this is still in discussion. The azure sdk team's previous discussion with me was not fruitful. I'm not actually on the azure sdk team, but was just trying to help. The team apparently wanted to make the changes themselves. Things just got worse imo.

if (!HttpClient.DefaultRequestHeaders.UserAgent.Contains<ProductInfoHeaderValue>(pInfoHeaderValue,
                    new ObjectComparer<ProductInfoHeaderValue>((left, right) => left.Product.Name.Equals(right.Product.Name, StringComparison.OrdinalIgnoreCase))))
                {
...
  • Created objects are still not properly disposed.

  • The locking strategy in ServiceClient does not make sense to me, and I think ServiceClient should just be a singleton per service.

Copy link

Choose a reason for hiding this comment

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

@EricDahlvang , yeah I'm in the same situation with you.I need to create ContainerInstanceManagementClient every request due to the different subscription id and token info.Creating a new ContainerInstanceManagementClient instance will create a new ServiceClient. So the lock seems useless in this condition
I think the right way to fix is to remove the part of setting user agent

string cleanedProductName = CleanUserAgentInfoEntry(productName);
HttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(cleanedProductName, version));
string cleanedProductName = CleanUserAgentInfoEntry(productName);
MergeUserAgentInfo(new ProductInfoHeaderValue(cleanedProductName, version));
Copy link
Member

Choose a reason for hiding this comment

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

What we really need is the deDuping of UserAgent collection.
Yes this unblocks you for the nullRef, but this has perf. impact and I would prefer a deDuping of UserAgent collection than what is implemented in your PR.
So if you can update your PR with 1 time deDuping of UserAgent collection that will be great, else we can do that.

Copy link
Author

Choose a reason for hiding this comment

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

I've made the requested changes.

Frankly, this method for deDuping UserAgent isn't enough for my use case. I'd like to use the constructor that allows me to pass in an HttpClient. However, I want to use a Static HttpClient ... and this code is not threadsafe. I believe a better option would be to not add UserAgent headers at all, if the consumer has provided their own HttpClient. What are your thoughts?

@shahabhijeet
Copy link
Member

@azuresdkci retest this please

@EricDahlvang
Copy link
Author

@shahabhijeet @azuresdkci

Is there something holding up this PR being merged?

@azuresdkci
Copy link
Contributor

Can one of the admins verify this patch?

@dsgouda dsgouda assigned dsgouda and shahabhijeet and unassigned dsgouda Apr 19, 2018
@EricDahlvang
Copy link
Author

I totally understand having difficulty with a PR someone submits, and you do not want to accept. If you have a different plan to handle the underlying issues I've attempted to address with this, please let me know. We can just close this PR without merging, and resolve these issues some other way if that is the preference of your team. From my perspective, I don't see any reason to just leave this sitting here without merging, without feedback and without discussion. I will understand if you want to just close this, but please address the underlying issues.

@shahabhijeet
Copy link
Member

@EricDahlvang opened a new PR that addresses multiple issues including avoiding duplicating userAgent strings.
#4529
Closing this PR against the above one.
Can you review the PR, will add you to that other review.

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.

5 participants