dotnet/aspnetcore
Auf GitHub ansehenTestServer.CreateClient : the HttpClient created didn't support well the cancellation.
Open
#5.938 geöffnet am 17. Sept. 2018
affected-fewarea-hostingarea-networkingbughelp wantedseverity-minor
Repository-Metriken
- Stars
- (37.933 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 16T 9h) (258 gemergte PRs in 30 T)
Beschreibung
Hello,
I just found a nasty bug on HttpClient created from TestServer. When I call a request which took 2 seconds if I cancel it after one second. The client created by test server didn't throw an OperationCancelledException.
Here the code with real httpClient :
var httpClient = new HttpClient();
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1)))
{
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("http://localhost:4242/TimeoutTest/Action2Secs")
};
await httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead, cts.Token);
}
The same code with client created by the class TestServer.
var httpClient = new testServer.CreateClient();
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1)))
{
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("http://localhost:4242/TimeoutTest/Action2Secs")
};
await httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead, cts.Token);
}