Skip to content

Commit

Permalink
Merge pull request #1408 from zooba/entry-race
Browse files Browse the repository at this point in the history
Fixes race condition from unloading files before clearing local information
  • Loading branch information
zooba committed Jul 7, 2016
2 parents 8e1b7c1 + 7a04a3c commit 85426a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Python/Product/Analyzer/Intellisense/AnalysisProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Collections.Generic;
using System.Reflection;
using Microsoft.PythonTools.Analysis;
using Microsoft.PythonTools.Infrastructure;
using Microsoft.PythonTools.Interpreter;
using Microsoft.PythonTools.Ipc.Json;
using Microsoft.PythonTools.Parsing;
Expand Down Expand Up @@ -310,6 +311,8 @@ public sealed class UnloadFileRequest : Request<Response> {

public int fileId;
public override string command => Command;

public override string ToString() => "{0}:{1}".FormatUI(command, fileId);
}


Expand All @@ -329,6 +332,8 @@ public sealed class FileUpdateRequest : Request<FileUpdateResponse> {
public FileUpdate[] updates;

public override string command => Command;

public override string ToString() => "{0}:{1} ({2} updates)".FormatUI(command, fileId, updates.Length);
}

public enum FileUpdateKind {
Expand Down
2 changes: 2 additions & 0 deletions Python/Product/Ipc.Json/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace Microsoft.PythonTools.Ipc.Json {
public class Request {
[JsonIgnore]
public virtual string command => null;

public override string ToString() => command;
}

public class GenericRequest : Request<Response> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1339,14 +1339,15 @@ class ExprWalker : PythonWalker {

internal async Task UnloadFileAsync(AnalysisEntry entry) {
_analysisComplete = false;
await SendRequestAsync(new AP.UnloadFileRequest() { fileId = entry.FileId }).ConfigureAwait(false);
AnalysisEntry removed;
_projectFiles.TryRemove(entry.Path, out removed);
_projectFilesById.TryRemove(entry.FileId, out removed);

_errorProvider.Clear(entry, ParserTaskMoniker);
_errorProvider.Clear(entry, UnresolvedImportMoniker);
_commentTaskProvider.Clear(entry, ParserTaskMoniker);

await SendRequestAsync(new AP.UnloadFileRequest() { fileId = entry.FileId }).ConfigureAwait(false);
}

internal void ClearAllTasks() {
Expand Down Expand Up @@ -1380,7 +1381,7 @@ class ExprWalker : PythonWalker {
if (conn == null) {
return default(T);
}
Debug.WriteLine(String.Format("{1} Sending request {0}", request.command, DateTime.Now));
Debug.WriteLine(String.Format("{1} Sending request {0}", request, DateTime.Now));
T res = defaultValue;
try {
res = await conn.SendRequestAsync(request, _processExitedCancelSource.Token).ConfigureAwait(false);
Expand All @@ -1391,7 +1392,7 @@ class ExprWalker : PythonWalker {
} catch (FailedRequestException e) {
_pyService.Logger.LogEvent(Logging.PythonLogEvent.AnalysisOpertionFailed, e.Message);
}
Debug.WriteLine(String.Format("{1} Done sending request {0}", request.command, DateTime.Now));
Debug.WriteLine(String.Format("{1} Done sending request {0}", request, DateTime.Now));
return res;
}

Expand Down

0 comments on commit 85426a5

Please sign in to comment.