You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Split from #17315 which contained multiple related bugs)
The following code demonstrates the problem. This test server will return response headers quickly. But will take 15 seconds to return response body. We cancel the ReadAsync() after 1 second. But the ReadAsync() task doesn't cancel until the 15 seconds has elapsed.
[Fact]publicasyncTaskResponseStreamRead_CancelUsingToken_TaskCanceledQuickly(){varstopwatch=newStopwatch();stopwatch.Start();using(varclient=newHttpClient())using(HttpResponseMessageresponse=awaitclient.GetAsync(s_fastHeadersSlowBodyServer,HttpCompletionOption.ResponseHeadersRead)){stopwatch.Stop();_output.WriteLine("Time to get headers: {0}",stopwatch.Elapsed.ToString());Assert.Equal(HttpStatusCode.OK,response.StatusCode);varcts=newCancellationTokenSource();Streamstream=awaitresponse.Content.ReadAsStreamAsync();byte[]buffer=newbyte[ResponseBodyLength];Taskignore=Task.Delay(newTimeSpan(0,0,1)).ContinueWith(_ =>{_output.WriteLine("Calling cts.Cancel() at: {0}",stopwatch.Elapsed.ToString());cts.Cancel();});stopwatch.Restart();awaitAssert.ThrowsAsync<TaskCanceledException>(()=>stream.ReadAsync(buffer,0,buffer.Length,cts.Token));stopwatch.Stop();_output.WriteLine("ReadAsync() completed at: {0}",stopwatch.Elapsed.ToString());Assert.True(stopwatch.Elapsed<newTimeSpan(0,0,3),"Elapsed time should be short");}}
@davidsh is it possible that this issue is also present in .Net Framework 4.6.2 and not fixed there (not sure how similar the different code bases are)?
I tried this out in two clients (UWP and WPF). UWP works after pulling in the latest packages, but the WPF app (targeting 4.6.2) is still unable to cancel ReadAsync calls.
Pulling in these Net Core libs on top of Net Framework did fix the issue (but introduced a lot of unrelated side effects).
Activity
oxfordemma commentedon Aug 22, 2016
@davidsh is it possible that this issue is also present in .Net Framework 4.6.2 and not fixed there (not sure how similar the different code bases are)?
I tried this out in two clients (UWP and WPF). UWP works after pulling in the latest packages, but the WPF app (targeting 4.6.2) is still unable to cancel
ReadAsynccalls.Pulling in these Net Core libs on top of Net Framework did fix the issue (but introduced a lot of unrelated side effects).
davidsh commentedon Aug 22, 2016
The codebases between .NET Framework 4.6.x is totally different than CoreFx.
So, it is possible that this bug exists there.
thewavelength commentedon Oct 19, 2016
@davidsh If I'm not totally wrong, I can reproduce this behavior in
1.0.0-preview2-003131- is this wanted?davidsh commentedon Oct 20, 2016
@thewavelength What is "1.0.0-preview2-003131"? This bug was fixed in .NET Core 1.0 RTM release.
If you can repro it, please attach a repro solution so that we can investigate. If so, please open a new issue for tracking.