Fix for : 4045: Cannot cancel a Query. Query runs too long. (And SMO update) (#780)

* Fix for : 4045: Cannot cancel a Query. Query runs too long.
HandleExecuteRequest was returning a task to awaiter - which was getting waited on. changed it to async function to start task in new thread and return nothing to awaiter . Also the cancellation token set by cancel request was getting checked only after making the connection to execute batches. Added an additional check for cancellation token befor the connection has been made.

Fix for 4319: Error showing dbs when using AAD in... 1.5.0-alpha.74
David has already created a new version of SMO nuget with the fix. - incorporating the same (150.18096.0-preview).

* Adding awaitable internal task for tests to run properly

* Adding more cancel tests
This commit is contained in:
udeeshagautam
2019-03-13 15:39:00 -07:00
committed by GitHub
parent a08666af0f
commit 5778dc7b01
9 changed files with 123 additions and 36 deletions

View File

@@ -226,7 +226,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
{
get
{
if (!HasExecuted)
if (!HasExecuted && !HasCancelled)
{
throw new InvalidOperationException("Query has not been executed.");
}
@@ -259,6 +259,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
}
}
/// <summary>
/// if the query has been cancelled (before execution started)
/// </summary>
public bool HasCancelled { get; private set; }
/// <summary>
/// The text of the query to execute
/// </summary>
@@ -280,6 +285,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
}
// Issue the cancellation token for the query
this.HasCancelled = true;
cancellationSource.Cancel();
}
@@ -368,9 +374,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
ReliableSqlConnection sqlConn = null;
try
{
// check for cancellation token before actually making connection
cancellationSource.Token.ThrowIfCancellationRequested();
// Mark that we've internally executed
hasExecuteBeenCalled = true;
// Don't actually execute if there aren't any batches to execute
if (Batches.Length == 0)
{
@@ -429,6 +438,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
}
catch (Exception e)
{
if (e is OperationCanceledException)
{
await BatchMessageSent(new ResultMessage(SR.QueryServiceQueryCancelled, false, null));
}
// Call the query failure callback
if (QueryFailed != null)
{