diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIHandle.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIHandle.cs index f9d92c82216c..b38cb2411667 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIHandle.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIHandle.cs @@ -56,7 +56,7 @@ internal abstract class SNIHandle /// /// SNI packet /// SNI error code - public abstract uint ReceiveAsync(ref SNIPacket packet, bool isMars = false); + public abstract uint ReceiveAsync(ref SNIPacket packet); /// /// Enable SSL diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIMarsConnection.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIMarsConnection.cs index e39b84735a68..a98dedfbc8ee 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIMarsConnection.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIMarsConnection.cs @@ -108,7 +108,7 @@ public uint ReceiveAsync(ref SNIPacket packet) { lock (this) { - return _lowerHandle.ReceiveAsync(ref packet, isMars: true); + return _lowerHandle.ReceiveAsync(ref packet); } } diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIMarsHandle.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIMarsHandle.cs index 1aa5f270fb55..4d079f6ad0bb 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIMarsHandle.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIMarsHandle.cs @@ -272,7 +272,7 @@ public override uint SendAsync(SNIPacket packet, bool disposePacketAfterSendAsyn /// /// SNI packet /// SNI error code - public override uint ReceiveAsync(ref SNIPacket packet, bool isMars = true) + public override uint ReceiveAsync(ref SNIPacket packet) { lock (_receivedPacketQueue) { diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNINpHandle.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNINpHandle.cs index 0e976020d0f3..67581e8d32c4 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNINpHandle.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNINpHandle.cs @@ -172,13 +172,13 @@ public override uint Receive(out SNIPacket packet, int timeout) } } - public override uint ReceiveAsync(ref SNIPacket packet, bool isMars = false) + public override uint ReceiveAsync(ref SNIPacket packet) { packet = new SNIPacket(_bufferSize); try { - packet.ReadFromStreamAsync(_stream, _receiveCallback, isMars); + packet.ReadFromStreamAsync(_stream, _receiveCallback); return TdsEnums.SNI_SUCCESS_IO_PENDING; } catch (ObjectDisposedException ode) diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs index f34bbf6bef5f..84a47740fabf 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs @@ -245,22 +245,13 @@ public void Reset() /// /// Stream to read from /// Completion callback - public void ReadFromStreamAsync(Stream stream, SNIAsyncCallback callback, bool isMars) + public void ReadFromStreamAsync(Stream stream, SNIAsyncCallback callback) { bool error = false; - TaskContinuationOptions options = TaskContinuationOptions.DenyChildAttach; - // MARS operations during Sync ADO.Net API calls are Sync over Async. Each API call can request - // threads to execute the async reads. MARS operations do not get the threads quickly enough leading to timeout - // To fix the MARS thread exhaustion issue LongRunning continuation option is a temporary solution with its own drawbacks, - // and should be removed after evaluating how to fix MARS threading issues efficiently - if (isMars) - { - options |= TaskContinuationOptions.LongRunning; - } - + stream.ReadAsync(_data, 0, _capacity, CancellationToken.None).ContinueWith(t => { - Exception e = t.Exception != null ? t.Exception.InnerException : null; + Exception e = t.Exception?.InnerException; if (e != null) { SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.TCP_PROV, SNICommon.InternalExceptionError, e); @@ -285,7 +276,7 @@ public void ReadFromStreamAsync(Stream stream, SNIAsyncCallback callback, bool i callback(this, error ? TdsEnums.SNI_ERROR : TdsEnums.SNI_SUCCESS); }, CancellationToken.None, - options, + TaskContinuationOptions.DenyChildAttach, TaskScheduler.Default); } diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIProxy.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIProxy.cs index 248e84a13d71..e0cd0a3dec4a 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIProxy.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIProxy.cs @@ -443,7 +443,7 @@ private SNINpHandle CreateNpHandle(DataSource details, long timerExpire, object /// SNI handle /// Packet /// SNI error status - public uint ReadAsync(SNIHandle handle, out SNIPacket packet, bool isMars = false) + public uint ReadAsync(SNIHandle handle, out SNIPacket packet) { packet = null; return handle.ReceiveAsync(ref packet); diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNITcpHandle.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNITcpHandle.cs index 9b0f12fb3ec2..448a48a9343c 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNITcpHandle.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNITcpHandle.cs @@ -537,13 +537,13 @@ public override uint SendAsync(SNIPacket packet, bool disposePacketAfterSendAsyn /// /// SNI packet /// SNI error code - public override uint ReceiveAsync(ref SNIPacket packet, bool isMars = false) + public override uint ReceiveAsync(ref SNIPacket packet) { packet = new SNIPacket(_bufferSize); try { - packet.ReadFromStreamAsync(_stream, _receiveCallback, isMars); + packet.ReadFromStreamAsync(_stream, _receiveCallback); return TdsEnums.SNI_SUCCESS_IO_PENDING; } catch (Exception e) when (e is ObjectDisposedException || e is SocketException || e is IOException) diff --git a/src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectManaged.cs index e6f9f0668e97..02c660263312 100644 --- a/src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -156,7 +156,7 @@ internal override uint CheckConnection() internal override object ReadAsync(out uint error, ref object handle) { SNIPacket packet; - error = SNIProxy.Singleton.ReadAsync((SNIHandle)handle, out packet, isMars: _parser.MARSOn); + error = SNIProxy.Singleton.ReadAsync((SNIHandle)handle, out packet); return packet; }