mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
fixed the issue with resources not disposed correctly (#439)
* fixed the issue with resources not disposed correctly * disposing language service at shutdown
This commit is contained in:
@@ -1119,9 +1119,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
throw new ArgumentException("sourceXml");
|
throw new ArgumentException("sourceXml");
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStream memoryStream = new MemoryStream();
|
using (MemoryStream memoryStream = new MemoryStream())
|
||||||
StreamWriter streamWriter = new StreamWriter(memoryStream);
|
{
|
||||||
|
using (StreamWriter streamWriter = new StreamWriter(memoryStream))
|
||||||
|
{
|
||||||
// Writes the xml to the memory stream
|
// Writes the xml to the memory stream
|
||||||
streamWriter.Write(sourceXml);
|
streamWriter.Write(sourceXml);
|
||||||
streamWriter.Flush();
|
streamWriter.Flush();
|
||||||
@@ -1141,6 +1142,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
|
|
||||||
return xmlDocument;
|
return xmlDocument;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -647,17 +647,20 @@ WHERE do.database_id = @DbID
|
|||||||
{ //If it's under v12 we need to query the master DB directly since that has the views containing the necessary information
|
{ //If it's under v12 we need to query the master DB directly since that has the views containing the necessary information
|
||||||
using (var conn = new SqlConnection(context.Server.ConnectionContext.ConnectionString))
|
using (var conn = new SqlConnection(context.Server.ConnectionContext.ConnectionString))
|
||||||
{
|
{
|
||||||
var cmd = new SqlCommand(dbSloQuery, conn);
|
using (var cmd = new SqlCommand(dbSloQuery, conn))
|
||||||
|
{
|
||||||
cmd.Parameters.AddWithValue("@DbID", db.ID);
|
cmd.Parameters.AddWithValue("@DbID", db.ID);
|
||||||
conn.Open();
|
conn.Open();
|
||||||
SqlDataReader reader = cmd.ExecuteReader();
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
this.configuredServiceLevelObjective = reader["configured_slo_name"].ToString();
|
this.configuredServiceLevelObjective = reader["configured_slo_name"].ToString();
|
||||||
this.currentServiceLevelObjective = reader["current_slo_name"].ToString();
|
this.currentServiceLevelObjective = reader["current_slo_name"].ToString();
|
||||||
break; //Got our service level objective so we're done
|
break; //Got our service level objective so we're done
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
//Altering the DB needs to be done on the master DB
|
//Altering the DB needs to be done on the master DB
|
||||||
using (var conn = new SqlConnection(this.context.ServerConnection.GetDatabaseConnection("master").ConnectionString))
|
using (var conn = new SqlConnection(this.context.ServerConnection.GetDatabaseConnection("master").ConnectionString))
|
||||||
{
|
{
|
||||||
var cmd = new SqlCommand();
|
using (var cmd = new SqlCommand())
|
||||||
|
{
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
conn.Open();
|
conn.Open();
|
||||||
|
|
||||||
@@ -205,6 +206,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
|||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Because we didn't use SMO to do the alter we should refresh the DB object so it picks up the correct properties
|
//Because we didn't use SMO to do the alter we should refresh the DB object so it picks up the correct properties
|
||||||
db.Refresh();
|
db.Refresh();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// Copyright (c) Microsoft. All rights reserved.
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using Microsoft.SqlTools.Credentials;
|
using Microsoft.SqlTools.Credentials;
|
||||||
using Microsoft.SqlTools.Extensibility;
|
using Microsoft.SqlTools.Extensibility;
|
||||||
using Microsoft.SqlTools.Hosting;
|
using Microsoft.SqlTools.Hosting;
|
||||||
@@ -13,7 +14,6 @@ using Microsoft.SqlTools.ServiceLayer.EditData;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Metadata;
|
using Microsoft.SqlTools.ServiceLayer.Metadata;
|
||||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Scripting;
|
using Microsoft.SqlTools.ServiceLayer.Scripting;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Main class for the Binding Queue
|
/// Main class for the Binding Queue
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BindingQueue<T> where T : IBindingContext, new()
|
public class BindingQueue<T> : IDisposable where T : IBindingContext, new()
|
||||||
{
|
{
|
||||||
private CancellationTokenSource processQueueCancelToken = new CancellationTokenSource();
|
private CancellationTokenSource processQueueCancelToken = new CancellationTokenSource();
|
||||||
|
|
||||||
@@ -313,5 +313,24 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (itemQueuedEvent != null)
|
||||||
|
{
|
||||||
|
itemQueuedEvent.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.BindingContextMap != null)
|
||||||
|
{
|
||||||
|
foreach (var item in this.BindingContextMap)
|
||||||
|
{
|
||||||
|
if (item.Value != null && item.Value.ServerConnection != null && item.Value.ServerConnection.SqlConnectionObject != null)
|
||||||
|
{
|
||||||
|
item.Value.ServerConnection.SqlConnectionObject.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
/// Main class for Language Service functionality including anything that requires knowledge of
|
/// Main class for Language Service functionality including anything that requires knowledge of
|
||||||
/// the language to perform, such as definitions, intellisense, etc.
|
/// the language to perform, such as definitions, intellisense, etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class LanguageService
|
public sealed class LanguageService: IDisposable
|
||||||
{
|
{
|
||||||
#region Singleton Instance Implementation
|
#region Singleton Instance Implementation
|
||||||
|
|
||||||
@@ -249,6 +249,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
{
|
{
|
||||||
Logger.Write(LogLevel.Verbose, "Shutting down language service");
|
Logger.Write(LogLevel.Verbose, "Shutting down language service");
|
||||||
DeletePeekDefinitionScripts();
|
DeletePeekDefinitionScripts();
|
||||||
|
this.Dispose();
|
||||||
await Task.FromResult(0);
|
await Task.FromResult(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1716,5 +1717,13 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (bindingQueue != null)
|
||||||
|
{
|
||||||
|
bindingQueue.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,10 +147,11 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
|||||||
Task<TaskResult> completedTask = null;
|
Task<TaskResult> completedTask = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
using (AutoResetEvent onCompletedEvent = new AutoResetEvent(initialState: false))
|
||||||
{
|
{
|
||||||
if (TaskToCancel != null)
|
if (TaskToCancel != null)
|
||||||
{
|
{
|
||||||
AutoResetEvent onCompletedEvent = new AutoResetEvent(initialState: false);
|
|
||||||
Task<TaskResult> cancelTask = Task.Run(() => CancelTaskAsync(TokenSource.Token, onCompletedEvent));
|
Task<TaskResult> cancelTask = Task.Run(() => CancelTaskAsync(TokenSource.Token, onCompletedEvent));
|
||||||
|
|
||||||
completedTask = await Task.WhenAny(performTask, cancelTask);
|
completedTask = await Task.WhenAny(performTask, cancelTask);
|
||||||
@@ -169,7 +170,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
|||||||
AddMessage(completedTask.Result.TaskStatus == SqlTaskStatus.Failed ? completedTask.Result.ErrorMessage : SR.TaskCompleted,
|
AddMessage(completedTask.Result.TaskStatus == SqlTaskStatus.Failed ? completedTask.Result.ErrorMessage : SR.TaskCompleted,
|
||||||
completedTask.Result.TaskStatus);
|
completedTask.Result.TaskStatus);
|
||||||
taskResult = completedTask.Result;
|
taskResult = completedTask.Result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user