-
Notifications
You must be signed in to change notification settings - Fork 312
Fixes "InvalidOperationException" errors by performing async operations in SemaphoreSlim #796
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0f27c26
Fixes "InvalidOperationException" errors by performing async write op…
cheenamalhotra aca1cc6
Add license header
cheenamalhotra 65ec669
Fix default include
cheenamalhotra 9ea1207
Suppress issue 422 from pipelines, till it gets fixed.
cheenamalhotra 7cc72ed
Fix Async + Mars perf issue
cheenamalhotra ddcfd41
Improvements
cheenamalhotra f6b5da4
Unblock Sync overrides
cheenamalhotra 3eaa757
Move release to finally
cheenamalhotra de07449
Implementing SNINetworkStream fixes issue 422 for non-encrypted TCP c…
cheenamalhotra acfcb35
Revert test change
cheenamalhotra 664529a
Change to async/await
cheenamalhotra dcd2531
Apply suggestions from code review
cheenamalhotra cd0153a
Reset locks
cheenamalhotra 72c54a8
Merge branch 'fix459' of https://github.com/cheenamalhotra/SqlClient …
cheenamalhotra 3e90787
Merge branch 'master' into fix459
cheenamalhotra b743e45
Simplified design as SemaphoreSlim is concurrent - confirmed.
cheenamalhotra 7d341af
Improve
cheenamalhotra f76e1c0
Revert unwanted changes
cheenamalhotra 10421a9
Adding queue back to maintain FIFO for extra security.
cheenamalhotra d6b71ec
Cleanup
cheenamalhotra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNISslStream.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Net.Security; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Data.SqlClient.SNI | ||
{ | ||
/// <summary> | ||
/// This class extends SslStream to customize stream behavior for Managed SNI implementation. | ||
/// </summary> | ||
internal class SNISslStream : SslStream | ||
{ | ||
private readonly ConcurrentQueueSemaphore _writeAsyncQueueSemaphore; | ||
private readonly ConcurrentQueueSemaphore _readAsyncQueueSemaphore; | ||
|
||
public SNISslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback) | ||
: base(innerStream, leaveInnerStreamOpen, userCertificateValidationCallback) | ||
{ | ||
_writeAsyncQueueSemaphore = new ConcurrentQueueSemaphore(1); | ||
_readAsyncQueueSemaphore = new ConcurrentQueueSemaphore(1); | ||
} | ||
|
||
// Prevent the ReadAsync's collision by running task in Semaphore Slim | ||
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) | ||
{ | ||
return _readAsyncQueueSemaphore.WaitAsync().ContinueWith<int>(t => base.ReadAsync(buffer, offset, count, cancellationToken).Result) | ||
.ContinueWith(t => _readAsyncQueueSemaphore.Release(t.Result)); | ||
} | ||
|
||
// Prevent the WriteAsync's collision by running task in Semaphore Slim | ||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) | ||
{ | ||
return _writeAsyncQueueSemaphore.WaitAsync().ContinueWith(t => base.WriteAsync(buffer, offset, count, cancellationToken)) | ||
.ContinueWith(t => _writeAsyncQueueSemaphore.Release()); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.