This project is read-only.

Race conditions with async Roslyn API

Topics: APIs, General
Oct 6, 2014 at 8:05 AM
Hi, I've got a question regarding the async APIs in Roslyn: is it allowed to have multiple outstanding calls to async methods?

The issue I'm facing is with the following code:
var markerTask = ScriptEditorUtilities.GetClassifiedSpansAsync(document, codeSpan);
var errorTask = ScriptEditorUtilities.GetDiagnosticsAsync(document);

// do other stuff ...

var markers = await markerTask.ConfigureAwait(true);
var errors = await errorTask.ConfigureAwait(true);
GetClassifiedSpansAsync calls Classifier.GetClassifiedSpansAsync() and GetDiagnosticsAsync calls Document.GetSemanticModelAsync().GetDiagnostics()

The calls are made from the WinForms UI Thread, but internally Roslyn sometimes (about 1 in 30 runs) will throw exceptions while loading an assembly because it (internally) is using the same FileStream from multiple threads without proper synchronization.

So the question: did I miss some guideline that only one async method can be outstanding? Or is this a bug inside Roslyn?
Oct 8, 2014 at 8:16 AM
The question has been answered on the linked issue, seems to have been a bug in Roslyn.