Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@stephentoub
Copy link
Member

We're employing a pattern in SslStream to avoid redundant code: we reuse the same code paths for both sync and async operations, with different interface implementations for each. The sync implementation has implementations that complete synchronously, and we then guarantee that the whole operation actually completes synchronously, even though it's implemented with async methods. We then .GetAwaiter().GetResult() to extract the result. Since by construction the task will have already completed, it's ok to do so, but it's difficult for a human to see this, and harder for an analyzer. Add an assert to both convey to an analyzer that we know what we're doing, and add a message for a human to understand it better. We can also remove an unnecessary "AsTask()" operation from the synchronous Write path, which should also remove a tiny bit of overhead.

We're employing a pattern in SslStream to avoid redundant code: we reuse the same code paths for both sync and async operations, with different interface implementations for each.  The sync implementation has implementations that complete synchronously, and we then guarantee that the whole operation actually completes synchronously, even though it's implemented with async methods.  We then .GetAwaiter().GetResult() to extract the result.  Since by construction the task will have already completed, it's ok to do so, but it's difficult for a human to see this, and harder for an analyzer.  Add an assert to both convey to an analyzer that we know what we're doing, and add a message for a human to understand it better. We can also remove an unnecessary "AsTask()" operation from the synchronous Write path, which should also remove a tiny bit of overhead.
@stephentoub stephentoub merged commit d301036 into dotnet:master Nov 3, 2019
@stephentoub stephentoub deleted the sslvaluetask branch November 3, 2019 13:58
@davidsh davidsh added this to the 5.0 milestone Nov 3, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
)

We're employing a pattern in SslStream to avoid redundant code: we reuse the same code paths for both sync and async operations, with different interface implementations for each.  The sync implementation has implementations that complete synchronously, and we then guarantee that the whole operation actually completes synchronously, even though it's implemented with async methods.  We then .GetAwaiter().GetResult() to extract the result.  Since by construction the task will have already completed, it's ok to do so, but it's difficult for a human to see this, and harder for an analyzer.  Add an assert to both convey to an analyzer that we know what we're doing, and add a message for a human to understand it better. We can also remove an unnecessary "AsTask()" operation from the synchronous Write path, which should also remove a tiny bit of overhead.

Commit migrated from dotnet/corefx@d301036
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants