TestServer: Copy the feature collection to mitigate multi-threading

This commit is contained in:
Chris Ross (ASP.NET) 2017-11-07 09:03:49 -08:00
parent 1e556e0b46
commit 64596d538b
1 changed files with 7 additions and 1 deletions

View File

@ -110,7 +110,13 @@ namespace Microsoft.AspNetCore.TestHost
{
// Sets HasStarted
await _responseFeature.FireOnSendingHeadersAsync();
_responseTcs.TrySetResult(_httpContext);
// Copy the feature collection so we're not multi-threading on the same collection.
var newFeatures = new FeatureCollection();
foreach (var pair in _httpContext.Features)
{
newFeatures[pair.Key] = pair.Value;
}
_responseTcs.TrySetResult(new DefaultHttpContext(newFeatures));
}
}