-
Notifications
You must be signed in to change notification settings - Fork 312
Merge | Remove OS-specific TdsParser files #3469
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
base: main
Are you sure you want to change the base?
Changes from all commits
aaa8161
a66fe7e
494e74a
1e677d0
6c84a21
0bb49cf
86f4c91
bb7ad23
f39e962
ef3ca3a
8bf5970
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,8 @@ | |
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.IO; | ||
#if NET | ||
using System.Security.Authentication; | ||
#else | ||
#if NETFRAMEWORK | ||
using System.Runtime.CompilerServices; | ||
#endif | ||
using System.Text; | ||
|
@@ -683,31 +682,10 @@ internal void EnableMars() | |
ThrowExceptionAndWarning(_physicalStateObj); | ||
} | ||
|
||
// HACK HACK HACK - for Async only | ||
// Have to post read to intialize MARS - will get callback on this when connection goes | ||
// down or is closed. | ||
|
||
IntPtr temp = IntPtr.Zero; | ||
|
||
RuntimeHelpers.PrepareConstrainedRegions(); | ||
try | ||
{ } | ||
finally | ||
{ | ||
_pMarsPhysicalConObj.IncrementPendingCallbacks(); | ||
|
||
error = SniNativeWrapper.SniReadAsync(_pMarsPhysicalConObj.Handle, ref temp); | ||
|
||
if (temp != IntPtr.Zero) | ||
{ | ||
// Be sure to release packet, otherwise it will be leaked by native. | ||
SniNativeWrapper.SniPacketRelease(temp); | ||
} | ||
} | ||
Debug.Assert(IntPtr.Zero == temp, "unexpected syncReadPacket without corresponding SNIPacketRelease"); | ||
if (TdsEnums.SNI_SUCCESS_IO_PENDING != error) | ||
error = _pMarsPhysicalConObj.PostReadAsyncForMars(_physicalStateObj); | ||
if (error != TdsEnums.SNI_SUCCESS_IO_PENDING) | ||
{ | ||
Debug.Assert(TdsEnums.SNI_SUCCESS != error, "Unexpected successful read async on physical connection before enabling MARS!"); | ||
Debug.Assert(error != TdsEnums.SNI_SUCCESS, "Unexpected successful read async on physical connection before enabling MARS!"); | ||
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj)); | ||
ThrowExceptionAndWarning(_physicalStateObj); | ||
} | ||
|
@@ -982,19 +960,25 @@ private void EnableSsl(uint info, SqlConnectionEncryptOption encrypt, bool integ | |
ThrowExceptionAndWarning(_physicalStateObj); | ||
} | ||
|
||
SslProtocols protocol = 0; | ||
|
||
// in the case where an async connection is made, encryption is used and Windows Authentication is used, | ||
// wait for SSL handshake to complete, so that the SSL context is fully negotiated before we try to use its | ||
// Channel Bindings as part of the Windows Authentication context build (SSL handshake must complete | ||
// before calling SNISecGenClientContext). | ||
error = SniNativeWrapper.SniWaitForSslHandshakeToComplete(_physicalStateObj.Handle, _physicalStateObj.GetTimeoutRemaining(), out uint protocolVersion); | ||
|
||
if (error != TdsEnums.SNI_SUCCESS) | ||
#if NET | ||
if (OperatingSystem.IsWindows()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My hope is eventually we will have compile time constants for this so we can replace the whole check with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Being able to use |
||
#endif | ||
{ | ||
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj)); | ||
ThrowExceptionAndWarning(_physicalStateObj); | ||
error = _physicalStateObj.WaitForSSLHandShakeToComplete(out protocol); | ||
if (error != TdsEnums.SNI_SUCCESS) | ||
{ | ||
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj)); | ||
ThrowExceptionAndWarning(_physicalStateObj); | ||
} | ||
} | ||
|
||
string warningMessage = ((System.Security.Authentication.SslProtocols)protocolVersion).GetProtocolWarning(); | ||
string warningMessage = protocol.GetProtocolWarning(); | ||
if (!string.IsNullOrEmpty(warningMessage)) | ||
{ | ||
if (!encrypt && LocalAppContextSwitches.SuppressInsecureTlsWarning) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get this at all ... isn't the point of a finally block to always run regardless of what happens in the try block, or what exceptions are caught? If there's nothing to run in the try block, doesn't it just immediately skip to the finally block? And if it does, what's the point of the try/finally in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part of the CER infrastructure. The finally block will always run, even in the event of a ThreadAbortException. Without the call to
PrepareConstrainedRegions
and atry
block, this wouldn't be guaranteed.I think the goal in this specific case is to make sure that if a thread is aborted while setting up the physical MARS connection, the same physical connection is left in a known-good state.