fix for issue 3123 (#729)

* fix for issue 3123

* using seperate thread to handle the requests and fixed a typo
This commit is contained in:
Alan Ren
2018-11-08 14:48:27 -08:00
committed by GitHub
parent 4f148a583b
commit 2cb7f682c5

View File

@@ -123,6 +123,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
/// Handle request to start a profiling session
/// </summary>
internal async Task HandleCreateXEventSessionRequest(CreateXEventSessionParams parameters, RequestContext<CreateXEventSessionResult> requestContext)
{
await Task.Run(async () =>
{
try
{
@@ -159,12 +161,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
await requestContext.SendError(new Exception(SR.CreateSessionFailed(e.Message)));
}
});
}
/// <summary>
/// Handle request to start a profiling session
/// </summary>
internal async Task HandleStartProfilingRequest(StartProfilingParams parameters, RequestContext<StartProfilingResult> requestContext)
{
await Task.Run(async () =>
{
try
{
@@ -191,12 +196,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
await requestContext.SendError(new Exception(SR.StartSessionFailed(e.Message)));
}
});
}
/// <summary>
/// Handle request to stop a profiling session
/// </summary>
internal async Task HandleStopProfilingRequest(StopProfilingParams parameters, RequestContext<StopProfilingResult> requestContext)
{
await Task.Run(async () =>
{
try
{
@@ -204,9 +212,28 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
if (session != null)
{
// Occasionally we might see the InvalidOperationException due to a read is
// in progress, add the following retry logic will solve the problem.
int remainingAttempts = 3;
while (true)
{
try
{
session.XEventSession.Stop();
await requestContext.SendResult(new StopProfilingResult { });
break;
}
catch (InvalidOperationException)
{
remainingAttempts--;
if (remainingAttempts == 0)
{
throw;
}
Thread.Sleep(500);
}
}
}
else
{
@@ -217,12 +244,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
await requestContext.SendError(new Exception(SR.StopSessionFailed(e.Message)));
}
});
}
/// <summary>
/// Handle request to pause a profiling session
/// </summary>
internal async Task HandlePauseProfilingRequest(PauseProfilingParams parameters, RequestContext<PauseProfilingResult> requestContext)
{
await Task.Run(async () =>
{
try
{
@@ -234,12 +264,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
await requestContext.SendError(new Exception(SR.PauseSessionFailed(e.Message)));
}
});
}
/// <summary>
/// Handle request to pause a profiling session
/// </summary>
internal async Task HandleGetXEventSessionsRequest(GetXEventSessionsParams parameters, RequestContext<GetXEventSessionsResult> requestContext)
{
await Task.Run(async () =>
{
try
{
@@ -263,6 +296,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
await requestContext.SendError(e);
}
});
}
/// <summary>
@@ -278,7 +312,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
BaseXEStore store = CreateXEventStore(connInfo, connection);
// get session names from the session list
List<string> results = store.Sessions.Aggregate(new List<string>(), (result, next) => {
List<string> results = store.Sessions.Aggregate(new List<string>(), (result, next) =>
{
result.Add(next.Name);
return result;
});
@@ -353,7 +388,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
connection.ServerConnection.ExecuteNonQuery(statement);
store.Refresh();
session = store.Sessions[sessionName];
if (session == null){
if (session == null)
{
throw new Exception(SR.SessionNotFound);
}
if (!session.IsRunning)