Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

From Feedback in issue 2149, Propagate CancellationToken in calls to TrySetCanceled: - #2608

Merged
davidsh merged 1 commit into
dotnet:masterfrom
josguil:PropagateCancelationToken-Issue2149
Aug 11, 2015
Merged

davidsh merged 1 commit into
dotnet:masterfrom
josguil:PropagateCancelationToken-Issue2149

Conversation

@josguil

@josguil josguil commented Aug 3, 2015

Copy link
Copy Markdown
Member

As a minor improvement, using the new TrySetCanceled overload, you could make this state.Tcs.TrySetCanceled(state.CancellationToken) ...
that just helps to ensure that the token is propagated to anyone getting an OperationCanceledException later on.

@SidharthNabar

Copy link
Copy Markdown

@davidsh

davidsh commented Aug 3, 2015

Copy link
Copy Markdown
Contributor

You should add a new test for this. You can add one in the FunctionalTests and either use a MockHandler or connect to the same server as the other functional test.

See this StackOverflow issue which reports a similar bug in .NET Framework (Desktop). It has repro code which could be re-purposed as your test case.

http://stackoverflow.com/questions/29319086/cancelling-an-httpclient-request-why-is-taskcanceledexception-cancellationtoke/29319312#29319312

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to leave this as true

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out that bug. A few remarks:

1.- I tried it , modifying it so the constructor of HttpClient receives a WinHttpHandler and touches the modified code. I could repro the results without my changes.

2.- After adding my changes the bug is still there, the property IsCancellationRequested doesn't seem to propagate to the cancellation token of the exception being thrown. I'm still investigating why and what part of the stack is actually in charge of throwing that exception.

3.- I know that my modified code is being touched because if I throw an exception just before calling TrySetCanceled I can see it. So I'm thinking of what other test could be helpful to verify this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidsh When you say to leave "locked" as true, do you mean for every project.lock.json or only for the one in System.Runtime.Extensions?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josguil My comment was about your change in this PR. You were changing the locked field from 'true' to 'false'. You need to leave it as 'true'. In general, once the project.lock.json file is made, the lock field should be set to 'true'.

If you look at other project.lock.json files in the CoreFx repo, you'll see that the locked field is set to 'true'.

@davidsh

davidsh commented Aug 3, 2015

Copy link
Copy Markdown
Contributor

Reference issue #2165

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a call to TrySetCanceled inside of the Register callback a few lines below this; presumably that should be updated as well, e.g.:

var cancellationTokenRegistration = state.CancellationToken.Register(s =>
{
    RequestState rs = (RequestState)s;
    rs.Tcs.TrySetCanceled(rs.CancellationToken);
}, state);

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. I'll investigate if the change is needed also there.

@josguil
josguil force-pushed the PropagateCancelationToken-Issue2149 branch 2 times, most recently from 88c4408 to fb83f00 Compare August 7, 2015 23:44
@josguil

josguil commented Aug 7, 2015

Copy link
Copy Markdown
Member Author

@CIPop @davidsh @SidharthNabar I did a new iteration, with tests added.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josguil I think we should have a larger discussion regarding configuration file locations and how these can be changed by the users to allow them to exercise the code against their own local servers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josguil

josguil commented Aug 8, 2015

Copy link
Copy Markdown
Member Author

@CIPop @davidsh PTAL.

@josguil

josguil commented Aug 10, 2015

Copy link
Copy Markdown
Member Author

@davidsh @CIPop PTAL

@CIPop

CIPop commented Aug 10, 2015

Copy link
Copy Markdown

LGTM

@davidsh

davidsh commented Aug 10, 2015

Copy link
Copy Markdown
Contributor

LGTM once the build goes GREEN.

@stephentoub

Copy link
Copy Markdown
Member

There's a test failure:

Discovering: System.Net.Http.WinHttpHandler.Unit.Tests
  Discovered:  System.Net.Http.WinHttpHandler.Unit.Tests
  System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
d:\j\workspace\dotnet_corefx_windows_debug_prtest\packages\Microsoft.DotNet.BuildTools.1.0.25-prerelease-00070\lib\tests.targets(130,5): warning MSB3073: The command "CoreRun.exe xunit.console.netcore.exe System.Net.Http.WinHttpHandler.Unit.Tests.dll  -xml testResults.xml -notrait category=nonwindowstests  -notrait category=OuterLoop -notrait category=failing " exited with code 1. [d:\j\workspace\dotnet_corefx_windows_debug_prtest\src\System.Net.Http.WinHttpHandler\tests\UnitTests\System.Net.Http.WinHttpHandler.Unit.Tests.csproj]
d:\j\workspace\dotnet_corefx_windows_debug_prtest\packages\Microsoft.DotNet.BuildTools.1.0.25-prerelease-00070\lib\tests.targets(141,5): error : One or more tests failed while running tests from 'System.Net.Http.WinHttpHandler.Unit.Tests' please check log for details! 

@davidsh

davidsh commented Aug 11, 2015

Copy link
Copy Markdown
Contributor

The failed test Is not in the HTTP libraries:

ChangedTests.FileSystemWatcher_Changed_PreSeededNestedStructure(includeSubdirectories: True)

@davidsh

davidsh commented Aug 11, 2015

Copy link
Copy Markdown
Contributor

@dotnet-bot test this please

…ts to verify it.

Addressing Feedback in GitHub

Renaming TestHandler to SendAsyncWinHttpMockHandler and adding missing spaces.

Added missing line in json file to use System.Runtime.InteropServices.RuntimeInformation.
@josguil
josguil force-pushed the PropagateCancelationToken-Issue2149 branch from 69fc88c to e76774d Compare August 11, 2015 21:00
davidsh added a commit that referenced this pull request Aug 11, 2015
…2149

From Feedback in issue 2149, Propagate CancellationToken in calls to TrySetCanceled:
@davidsh
davidsh merged commit 3df3655 into dotnet:master Aug 11, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants