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

Make federation implementation async and fix memory leak #4481

Merged
merged 2 commits into from
Jan 26, 2021

Conversation

mconnew
Copy link
Member

@mconnew mconnew commented Jan 5, 2021

Implemented BeginGetTokenCore and EndGetTokenCore to provide async implementation and fixed memory leak around ChannelFactory and channel lifetime.
Fixes #4462
Fixes #4461

@mconnew mconnew requested a review from brentschmaltz January 5, 2021 19:53
@mconnew
Copy link
Member Author

mconnew commented Jan 5, 2021

@brentschmaltz, can you take a look at this. I've tidied some things up in the process of fixing a couple of issues.


namespace System.ServiceModel.Security
{
interface ISecurityCommunicationObject

This comment was marked as resolved.

@@ -487,7 +487,7 @@ protected internal override async Task OnOpenAsync(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
SetupSessionTokenProvider();
SecurityUtils.OpenTokenProviderIfRequired(_sessionTokenProvider, timeoutHelper.RemainingTime());
await SecurityUtils.OpenTokenProviderIfRequiredAsync(_sessionTokenProvider, timeoutHelper.RemainingTime());
Copy link
Contributor

@brentschmaltz brentschmaltz Jan 21, 2021

Choose a reason for hiding this comment

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

should you have .ConfigureAwait(false) on these async methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not needed. I hated the idea of littering my code everywhere with ConfigureAwait because it's messy, and it only takes missing one to create a difficult to find bug. So instead I have some code which is called when calling WCF using an async contract which checks if you are using a non-default sync context or a non-default task scheduler, and if you are, forces an artificial continuation into the worker thread pool. So this code is guaranteed to not need ConfigureAwait. ConfigureAwait is needed if you might go async. If you are guaranteed to always go async (and WCF always does as it always does network IO which requires a response), then you can just forcibly go async from the start.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, cool just checking.
If you have a controlled call graph, you are probably OK,
We created a Roslyn Code Analyzer to check for our other libraries we have many entry points.

@mconnew What was the memory leak?

Copy link
Member Author

Choose a reason for hiding this comment

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

The memory leak was not closing the channel. The channel factory will hold on to the channel in an internal list. Each call would create a new instance which would accumulate instances. The fix is to close the channel after usage. Also we now close the channel factory when the parent channel factory is closed as that closes the token provider.

@HongGit HongGit merged commit ddd6927 into dotnet:master Jan 26, 2021
HongGit added a commit that referenced this pull request Jan 27, 2021
* Fix memory leak and add async token getting impl

* Make WSFed implementation async and fix memory leak

Co-authored-by: Matt Connew <matt.connew@microsoft.com>

Co-authored-by: Matt Connew <mconnew@microsoft.com>
Co-authored-by: Matt Connew <matt.connew@microsoft.com>
@mconnew mconnew deleted the AsyncFederation branch October 11, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants