mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-27 01:25:42 -05:00
Fix tools service crash + improve server edition naming (#506)
* Fix https://github.com/Microsoft/vscode-mssql/issues/986 and add better server edition naming - Fixed a number of issues related to the binding queue, specifically the fact that it didn't capture exceptions that occurred on the binding thread. This caused the thread to crash the service. - The root cause of the error was when you get a connection error during init of the SmoMetadataProvider which threw an exception. Because of this no Binder was created, and the code would null ref later during processing - Added logic to handle null ref issue and other related code - Added a unit test for the new error handling path, and supported still returning some value in this case - Separately, have a fix for an issue where the edition is shown as "SQL Azure" for all Azure connections. Fixing to be "Azure SQL DB" for this case and handle when the database reports as DW or Stretch instead. This maps better to users concept of what the edition should be and avoids returning what is an outdated term. * Messed up the test - fixing this by returning the expected return object
This commit is contained in:
@@ -9,6 +9,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using System.Linq;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
{
|
||||
@@ -64,6 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
string key,
|
||||
Func<IBindingContext, CancellationToken, object> bindOperation,
|
||||
Func<IBindingContext, object> timeoutOperation = null,
|
||||
Func<Exception, object> errorHandler = null,
|
||||
int? bindingTimeout = null,
|
||||
int? waitForLockTimeout = null)
|
||||
{
|
||||
@@ -78,6 +80,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
Key = key,
|
||||
BindOperation = bindOperation,
|
||||
TimeoutOperation = timeoutOperation,
|
||||
ErrorHandler = errorHandler,
|
||||
BindingTimeout = bindingTimeout,
|
||||
WaitForLockTimeout = waitForLockTimeout
|
||||
};
|
||||
@@ -92,6 +95,23 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
return queueItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a particular binding context is connected or not
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public bool IsBindingContextConnected(string key)
|
||||
{
|
||||
lock (this.bindingContextLock)
|
||||
{
|
||||
IBindingContext context;
|
||||
if (this.BindingContextMap.TryGetValue(key, out context))
|
||||
{
|
||||
return context.IsConnected;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or creates a binding context for the provided context key
|
||||
/// </summary>
|
||||
@@ -270,9 +290,20 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
// run the operation in a separate thread
|
||||
var bindThread = new Thread(() =>
|
||||
{
|
||||
result = queueItem.BindOperation(
|
||||
bindingContext,
|
||||
cancelToken.Token);
|
||||
try
|
||||
{
|
||||
result = queueItem.BindOperation(
|
||||
bindingContext,
|
||||
cancelToken.Token);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(LogLevel.Error, "Unexpected exception on the binding queue: " + ex.ToString());
|
||||
if (queueItem.ErrorHandler != null)
|
||||
{
|
||||
result = queueItem.ErrorHandler(ex);
|
||||
}
|
||||
}
|
||||
}, BindingQueue<T>.QueueThreadStackSize);
|
||||
bindThread.Start();
|
||||
|
||||
@@ -282,7 +313,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
queueItem.Result = result;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
cancelToken.Cancel();
|
||||
|
||||
// if the task didn't complete then call the timeout callback
|
||||
@@ -298,7 +329,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
// wait for the operation to complete before releasing the lock
|
||||
bindThread.Join();
|
||||
bindingContext.BindingLock.Set();
|
||||
});
|
||||
}).ContinueWithOnFaulted(t => Logger.Write(LogLevel.Error, "Binding queue threw exception " + t.Exception.ToString()));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user