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