Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ManagedHandler] Improve cancellation support when sending/receiving data #23138

Closed
stephentoub opened this issue Aug 11, 2017 · 10 comments
Closed
Assignees
Labels
disabled-test The test is disabled in source code against the issue enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@stephentoub
Copy link
Member

The ManagedHandler_CancellationTest tests are disabled because sockets don't support canceling individual operations. We might be able to address this once https://github.com/dotnet/corefx/issues/22608 is implemented and the associated cancellation support is enabled. We could also employ a variety of workarounds, including ending the whole request on cancellation by disposing of the connection, wrapping the operations in ones that can be canceled even though the underlying operation may continue running, etc.

@stephentoub stephentoub changed the title ManagedHandler: Improve cancellation support ManagedHandler: Improve cancellation support when sending/receiving data Aug 11, 2017
@WinCPP
Copy link
Contributor

WinCPP commented Oct 21, 2017

@stephentoub Before submitting any fix, I wanted to witness the error, so uncommented the associated test ManagedHandler_CancellationTest at this link where I found reference for this issue dotnet/corefx#23141. I also commented of the reference to ActiveIssue #21400 at this line.

Still, I am not able to reproduce the issue by giving command msbuild /t:RebuildAndTest in the folder ./src/System.Net.Http/tests/FunctionalTests where the test resides. I even tried with parameter /p;framework=netcoreapp to msbuild command.

Am I missing something? Appreciate your inputs.

@stephentoub
Copy link
Member Author

@WinCPP, the test is marked [OuterLoop], so you need to add /p:Outerloop=true to the msbuild command.

@WinCPP
Copy link
Contributor

WinCPP commented Oct 26, 2017

Hi @stephentoub , I think I have some solution. The method GetAsync_ResponseContentRead_CancelUsingTimeoutOrToken_TaskCanceledQuickly (link) annotated with attribute ActiveIssue #21400 no more fails. However I noticed that the test case 'ReadAsStreamAsync_ReadAsync_Cancel_TaskCanceledQuickly' (link) in the same file fails i.e. blocks, on my PC and, without commenting it out, I am not able to test the GetAsync... method.

I am not sure if ReadAsStreamAsync_ReadAsync_Cancel_TaskCanceledQuickly should block; it doesn't have any ActiveIssue annotation for netcoreapp framework. Please let me know if this is expected behavior on PC.

Also should I raise a PR for whatever code changes I have done...? Appreciate your inputs even if I am seeing the above mentioned issues?

@stephentoub
Copy link
Member Author

However I noticed that the test case 'ReadAsStreamAsync_ReadAsync_Cancel_TaskCanceledQuickly' (link) in the same file fails i.e. blocks

That would seem to be due to your changes then. It's currently passing on .NET Core.

@stephentoub
Copy link
Member Author

Also should I raise a PR for whatever code changes I have done...?

Sure, but I'm not sure how you'll be successful at this presently, given that the underlying sockets don't yet have actual support for cancellation enabled. What is the solution you're attempting?

@WinCPP
Copy link
Contributor

WinCPP commented Nov 23, 2017

Hi @stephentoub,

The solution that I am attempting is based on one of the ways that you mentioned in the opening comment for this issue, quoted below,

wrapping the operations in ones that can be canceled even though the underlying operation may continue running, etc.

I came across this blog of yours on which the solution is based. I understand that it may not be clean solution but it kind of adheres to one of the suggested solutions (for now until sockets get support for cancellation)...

I am fine tuning the code and also checking why ReadAsStreamAsync_ReadAsync_Cancel_TaskCanceledQuickly hangs... else will publish a PR for whatever I have coded in a day or two...

@WinCPP
Copy link
Contributor

WinCPP commented Nov 26, 2017

Hi @stephentoub I could make some progress on this. As for the hang in ReadAsStreamAsync_ReadAsync_Cancel_TaskCanceledQuickly, I found that it needs separate fix in 'ContentLengthReadStream' as after the response has been obtained, since ContentLengthReadStream doesn't handle cancellation via token and hence the hang. I am working on this. Also instead of allowing the underlying operation to continue, I am trying to find a way to close the httpconnection or the underlying stream (NetworkStream) so that there is an IOException or ObjectDisposedException, either of them triggered because the connection and / or the stream was disposed.

WinCPP referenced this issue in WinCPP/corefx Nov 28, 2017
Support CancellationToken for ManagedHandler
WinCPP referenced this issue in WinCPP/corefx Nov 28, 2017
Support CancellationToken for ManagedHandler
@WinCPP
Copy link
Contributor

WinCPP commented Dec 5, 2017

Hi @stephentoub thanks for the inputs in this comment. I will try working on it for dotnet/corefx#24430 and then make use of it here...

@karelz karelz changed the title ManagedHandler: Improve cancellation support when sending/receiving data [ManagedHandler] Improve cancellation support when sending/receiving data Dec 29, 2017
@geoffkizer
Copy link
Contributor

@stephentoub per our email discussion, sounds like you have a solution for this...

@stephentoub
Copy link
Member Author

We can do something similar to what WinCPP was working on. I'm working through some of the more intricate details. It's far from ideal, but I think it'll be shippable.

@stephentoub stephentoub self-assigned this Feb 8, 2018
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
disabled-test The test is disabled in source code against the issue enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

4 participants