Commit Graph
2059 Commits
Author SHA1 Message Date
Stephen Toub 413639ccd2 Add standalone HTTP stress test (dotnet/corefx#39021)
* Add standalone HTTP stress test

This is a simple standalone stress test that launches Kestrel in-proc, creates an HttpClient, and then concurrently makes lots of requests of varying kinds from the client to the server.  It's already discovered a plethora of issues in our HTTP/2 implementation, so I'm checking it in hopes that it can help to enable others to discover more.

* Address PR feedback


Commit migrated from https://github.com/dotnet/corefx/commit/3298cd55f840a8a3fab4450ac64ff3547073f651
2019-06-28 09:11:09 -04:00
Stephen Toub cec2617e81 Add more HTTP2 tracing (dotnet/corefx#39011)
Commit migrated from https://github.com/dotnet/corefx/commit/b8761d4848d42040c81ec25c8b51fd386b97f5f4
2019-06-27 21:24:48 -04:00
Stephen Toub c3967f2028 Fix HTTP2 duplex communication with Expect: 100-continue (dotnet/corefx#38995)
Duplex communication (allowing the request body to continue sending as the response body is processed) is currently broken with Expect: 100-continue: it's waiting for the request body to send before it'll return the stream for the response body to the caller.  The fix is to simplify the code, and minimize the special handling for Expect: 100-continue to just control if/when the request body is sent, rather than forking all of the logic around the handling of the request/response.

As part of diagnosing this, I added a lot more tracing, which I'm also including.

I also streamlined the CreditManager's wait list to make it slimmer.

Commit migrated from https://github.com/dotnet/corefx/commit/1833ec4769749dfce2b6dadad5882f208b499796
2019-06-27 19:30:11 -04:00
Stephen Toub 718d1968e4 Stop disposing of the proxy in HttpConnectionPoolManager.Dispose (dotnet/corefx#38991)
SocketsHttpHandler doesn't own the proxy its given; the lifetime of that proxy is up to the developer supplying it.  We may also end up using a global proxy instance if the developer hasn't explicitly supplied one.  However, SocketsHttpHandler's internal HttpConnectionPoolManager was disposing of this proxy instance on its disposal.  For proxies that implement IDisposable, as our global default proxy does, that can be very problematic; on Windows, our default proxy has a SafeHandle, and once its disposed, every subsequent request to the proxy will fail (an exception gets thrown and then internally eaten). The fix is simply to stop disposing a proxy instance we don't own.

While investigating this, I also made a few style tweaks to WinInetProxyHelper, removing private property setters, so as to better be able to see that certain values were readonly and never changed after construction.

Commit migrated from https://github.com/dotnet/corefx/commit/c6a849b8d24fc48bb0bbdb9f9165752a4a19459b
2019-06-27 19:29:23 -04:00
Geoff Kizer 45cd108dbf improve write buffer management and fix buffer size calculation in SendHeadersAsync (dotnet/corefx#38953)
* improve write buffer management and fix buffer size calculation in SendHeadersAsync

* review feedback


Commit migrated from https://github.com/dotnet/corefx/commit/6c6545143ac5bd4c438fad790899124312e1ffe1
2019-06-26 17:59:38 -04:00
Geoff Kizer 460217668c Merge pull request dotnet/corefx#38918 from geoffkizer/ignoreframesonclosedstream
ignore invalid frames on closed streams

Commit migrated from https://github.com/dotnet/corefx/commit/b9c89c4fe2454268a5e883ab269c877287f703ed
2019-06-26 12:31:58 -07:00
Jose Perez Rodriguez 275f6d0636 Making Exceptions serializable (dotnet/corefx#38893)
* Making Exceptions serializable

* Remove EventLog serialization exceptions from tests since they won't work on non-Windows platforms

* Fix build and add internal exceptions as well

* Add parameter-less constructor to RethrowException

* Adding PR Feedback

* Fix allConfigurations build


Commit migrated from https://github.com/dotnet/corefx/commit/7075587321a1b6b59248b1a6c7ea04fc803eab96
2019-06-26 11:59:59 -07:00
Geoff Kizer 370497ddbb fix connection level window accounting
Commit migrated from https://github.com/dotnet/corefx/commit/50b8897591b64c0cecc4561b6a314c4149350bef
2019-06-26 09:29:55 -07:00
Cory Nelson f8df117c02 Add HPACK integer validation to prevent wrapping and overlong encodings. (dotnet/corefx#38910)
* Add HPACK integer validation to prevent wrapping and overlong encodings. Resolves dotnet/corefx#38626.
* Improve documentation and add an assert to help avoid confusion and misuse of IntegerDecoder.StartDecode.

Commit migrated from https://github.com/dotnet/corefx/commit/5b29cd3efe43f83bee732263e4113448ae60d4d3
2019-06-26 09:16:08 -07:00
Geoff Kizer 7cf69c05d9 ignore frame processing callbacks on aborted streams
Commit migrated from https://github.com/dotnet/corefx/commit/281fdc6ba485126258466ea5c1486c79c46f8dbb
2019-06-26 09:07:01 -07:00
Geoff Kizer d6829bd98b ignore invalid frames on closed streams
Commit migrated from https://github.com/dotnet/corefx/commit/10ae10869a86e0ad9dc2d789b2da0c9b9acec2c1
2019-06-26 01:47:41 -07:00
Cory Nelson 00b8e9362e Implement MaxResponseHeadersLength for HTTP2 (dotnet/corefx#38560)
Implement MaxResponseHeadersLength for HTTP2. Resolves dotnet/corefx#35528.
Implement huffman-coded header support in Http2LoopbackServer.
Move HuffmanDecodingTests from functional to unit tests to avoid reflection.

Commit migrated from https://github.com/dotnet/corefx/commit/f0ec881bbb7945e35e3cf6862ea309b1143659f7
2019-06-26 00:04:36 -07:00
Stephen Toub 5766ac26a1 Remove faulty Http2Stream asserts (dotnet/corefx#38842)
These asserts are only valid if we're still holding the lock, which we're not.

Commit migrated from https://github.com/dotnet/corefx/commit/3c0d8436115c3d6905cd46d37fde980f73281995
2019-06-24 17:14:34 -04:00
Cory Nelson acc1b5f9dd Merge pull request dotnet/corefx#38832 from dotnet/stephentoub-disabletest
Disable Http2_FlowControl_ClientDoesNotExceedWindows test

Commit migrated from https://github.com/dotnet/corefx/commit/db1ef41efc7757bc88c52f46141092611855f2b0
2019-06-24 11:59:06 -07:00
Stephen Toub b63f77f3e5 Minor follow-ups/cleanups in Http2Connection and Http2Stream (dotnet/corefx#38817)
- Fix/adjust several uses of string interpolation in SocketsHttpHandler.
- Remove a Task.WhenAny allocation from SendAsync in the common case where there is no request content or where the request content sending completes synchronously.
- In GetWaiterTask use CT.UnsafeRegister instead of Register, as ExecutionContext, as the callback doesn't need context flowed.
- In GetWaiterTask, avoid allocating an unnecessary Task for the _waitSource if the token isn't cancelable.
- In GetWaiter task's cancellation callback, avoid allocating an OCE not associated with the wait.  Instead, just complete the waiter, and then rely on the subsequent cancellation check to propagate cancellation appropriately.
- Use CompareExchange to write to _abortException so that _abortException never changes its value once it's non-null.  We currently have several code paths that check the type of _abortException and then do something based on it, and that could cause issues if its type could change between the check and the action.
- Clean up HTTP2 SendAsync method, e.g. remove unnecessary tmps, remove duplicated await, use slightly more descriptive variable names, only wrap OCE with one for cancellationToken if cancellationToken has had cancellation requested.
- Replace a use of ExceptionDispatchInfo.Throw with just throw.  The former should be used when and only when throwing an exception object that may previously have been thrown; in this case we're throwing a new object that was never thrown before.
- Add detailed comment describing thread-safety around Http2Stream._waitSource
- Clean up a few comments
- Add some missing .ConfigureAwait(false) in loopback servers

Commit migrated from https://github.com/dotnet/corefx/commit/e771af6f93fe4bdc9e6172563e42422d5fdd30ff
2019-06-24 14:58:09 -04:00
Stephen Toub 84d62da976 Disable Http2_FlowControl_ClientDoesNotExceedWindows test
Commit migrated from https://github.com/dotnet/corefx/commit/99d5257629744a6683ed3724fb8fa24852a4af86
2019-06-24 14:53:53 -04:00
Cory Nelson 0d25902aa6 HTTP2: Fix InboundWindowSize_Exceeded_Throw failure under load (dotnet/corefx#38736)
* Resolves dotnet/corefx#38708. Test tegression caused by different behavior under high load.

* Improve comment explaining inconsistency of exception source.


Commit migrated from https://github.com/dotnet/corefx/commit/6a81e6195005a9edb125d67e5865b1db1403838c
2019-06-24 10:43:58 -07:00
Tomas Weinfurt c333cd0ecb follow up on duplex operation for HTTP/2 (dotnet/corefx#38226)
* follow up on duplex operation

* updates

* add test for cancelation

* log responseHeadersTask if bodyTask fails first

* improve cancelation

* feedback from review

* update SendAsync_ConcurentSendReceive_Fail test

* feedback from review

* update SendSettingsAckAsync

* more HTTP/2 cancelation tests

* update test to accept any derivative from OperationCanceledException

* feedback from review

* roll-back changes in AcceptConnectionAsync


Commit migrated from https://github.com/dotnet/corefx/commit/cad5159981f518f455be3528d0ee8eca2e00742a
2019-06-23 14:42:52 -07:00
Cory Nelson de8f8121c0 Improve comment explaining inconsistency of exception source.
Commit migrated from https://github.com/dotnet/corefx/commit/0f966e368fef859e578c55b45bbdd7539a42405d
2019-06-21 09:32:49 -07:00
Krzysztof Wicher 977bca97b2 Fix failing PostAsyncExpect100Continue_LateForbiddenResponse_Ok (dotnet/corefx#38742)
* PostAsyncExpect100Continue: Keep client alive until server finishes

* replace MRE with ShutdownIgnoringErrorsAsync


Commit migrated from https://github.com/dotnet/corefx/commit/bff9c7b2ac6b0608f555b0d4b82b5ffb983a8f2f
2019-06-20 21:06:59 -07:00
Cory Nelson b8fadafa3e Resolves dotnet/corefx#38708. Test tegression caused by different behavior under high load.
Commit migrated from https://github.com/dotnet/corefx/commit/9182532968d95f74be7df222318e52cc0834553f
2019-06-20 11:37:11 -07:00
Eric StJohn ec28e169dd Disable SocketsHttpHandlerTest_Http2.InboundWindowSize_Exceeded_Throw (dotnet/corefx#38722)
Test is consistently failing in CI.

Commit migrated from https://github.com/dotnet/corefx/commit/468355e66daf9eaeb1978703fa6365cd1e37e644
2019-06-20 09:56:14 -04:00
Krzysztof Wicher 3b182f8605 Add test support for multiple connections in Http2 (dotnet/corefx#38561)
* Add test support for multiple connections in Http2

* manual merge conflict fix, fix recently broken test (also in dotnet/corefx#38694)


Commit migrated from https://github.com/dotnet/corefx/commit/290a6e54a482ee950c4b812ad85f8de2d795932f
2019-06-19 16:34:29 -07:00
Cory Nelson 32ad3e2a62 Add HTTP2 receive window size enforcement test. (dotnet/corefx#38623)
* Add test for inbound window size enforcement. Resolves dotnet/corefx#35653.
* Correct timeout handling of Http2LoopbackServer.

Commit migrated from https://github.com/dotnet/corefx/commit/3863ec17c8ea61e72ef2240f23e4518788a2e8ae
2019-06-19 10:38:22 -07:00
Stephen Toub 8c3432f15f Adapt existing HttpClientMiniStress tests to support HTTP/2 (dotnet/corefx#38619)
This adapts the existing HttpClientMiniStress tests to run with HTTP/2 as well as HTTP/1.1.  Some caveats, though:
- All of these existing tests spin up a new server per request, so they're not stressing arguably the most important aspect of the client's HTTP/2 implementation, that of sharing the single connection across all requests.  Our loopback server is not currently robust enough to handle concurrent requests; we should look at switching over to using Kestrel.
- The tests run really slowly, ~40x slower than for HTTP/1.1.  However, the HTTP/1.1 tests are non-SSL, these are of course SSL, and it looks like that's actually the difference.  In particular, something about how our test server gets its test certificate appears to be taking the vast majority of the time. (We should separately see if we could tweak that, not just for this purpose, but more so to help speed up the whole suite.)

Commit migrated from https://github.com/dotnet/corefx/commit/a7c893ab3d3e50b11c7fa2338882c8964e0a290d
2019-06-18 18:08:38 -04:00
Stephen Toub 5a26d63e4b Add missing .ConfigureAwait(false) in HttpConnectionPool (dotnet/corefx#38610)
Commit migrated from https://github.com/dotnet/corefx/commit/3b2707b4b672af99d9d7ac3d57352099f1ff3ff1
2019-06-17 16:25:38 -04:00
Stephen Toub 43b2241491 Change DiagnosticsHandler to special-case base cancellation exception (dotnet/corefx#38601)
It should be treating all OperationCanceledExceptions as cancellation, not just TaskCanceledException.

Commit migrated from https://github.com/dotnet/corefx/commit/dd6b0669bec5ac3b72b2b3a015f42c403c3ec0f1
2019-06-17 16:25:23 -04:00
Viktor Hofer 5f98ba6a2b Enable project restore for test projects (dotnet/corefx#38151)
* Factor out repo restore into seperate props/targets

* Use configuration system msbuild sdk

* Remove XUnit.Runtime.depproj

* Remove TargetGroup usages in test projects

* Fix ILLink configuration

The ILLink package contains netcoreapp2.0 assets which are compatible
with netstandard2.0. Removing the old TargetFramework to restore
successfully.

* Remove usages from TargetGroup in Directory.Build.props

* Remove dead net4* configurations

* Change tests.builds to tests.proj sdk proj

* Make externals dir proj an sdk project

* Consume Microsoft.DotNet.CoreFxTesting as an msbuild sdk

* Use runtimeconfig.template.json

* Remove SupplementalTestData

* Map shared framework version to product version

* Stop binplacing tests

* Move some tool depprojs to targets during restore

* Remove dead code

* Use PackageReference instead of RefFromRuntime in test

* Disable using an apphost

* Copy compression testdata manually cause unicode bug

* Remove target batching in optimizationData

* Reference packaging tools from CoreFx.Private.TestUtilities


Commit migrated from https://github.com/dotnet/corefx/commit/c4c1985531cc1f25c805bbc4801b85c98e0dfee0
2019-06-15 21:27:13 +02:00
Cory Nelson ae79b2383f HPACK fixes and tests (dotnet/corefx#38324)
* HPACK correctness tests/updates. Resolves dotnet/corefx#31316.

Fixes:
- Fix check allowing out-of-bounds write in IntegerEncoder when an integer requires more than one byte and there is not enough buffer space.
- Encode Content-Type with a "Literal Header Without Indexing -- Indexed Name" rather than with a literal name.

Updates: (ported from ASP.NET HPACK code)
- Dynamic table size update must be the first instruction in the header block. Throw an exception when not the case.
- Throw an exception when we've reached the end of header data and we are still mid-parse.

New:
- Asserts, documentation, and tests for IntegerEncoder and IntegerDecoder.
- Tests to verify HttpClient is correctly encoding the different variants of headers.
- HPackDecoder tests (ported from ASP.NET)

* Address review feedback and fix CI.

* Address review feedback.

* Fix licensing to use ASP.NET's licensing. Add a TPN.


Commit migrated from https://github.com/dotnet/corefx/commit/ed526597f3f0d4653588ba0129fcaf18e2e5a4ef
2019-06-12 09:46:28 -07:00
David Shulman 78c12983dd Use HTTP Host header for Kerberos auth SPN calculation (dotnet/corefx#38465)
Fixed SocketsHttpHandler so that it will use the request's Host header,
if present, as part of building the Service Principal Name (SPN) when
doing Kerberos authentication. This now matches .NET Framework behavior.

Contributes to dotnet/corefx#34697 and dotnet/corefx#27745

Commit migrated from https://github.com/dotnet/corefx/commit/6cb854630083aac733d5b8001b266b872b56748e
2019-06-11 19:53:55 -07:00
Stephen Toub c61ef9bace Change EstablishConnectionAndProcessOneRequestAsync test method to use WhenAllOrAnyFailed (dotnet/corefx#38462)
* Change EstablishConnectionAndProcessOneRequestAsync test method to use WhenAllOrAnyFailed

CI is currently hanging when the client operation fails in a way that the server never hears about the request, and waits forever.

* Address PR feedback


Commit migrated from https://github.com/dotnet/corefx/commit/0b5479dde70fc565c5edefac4259578865496e84
2019-06-11 13:01:14 -07:00
Cory Nelson 13097de229 Resolves dotnet/corefx#37250. Re-enable tests that dotnet/corefx#38038 resolved. (dotnet/corefx#38461)
Commit migrated from https://github.com/dotnet/corefx/commit/5f5925c0c1a3a87e870db36ca6acce81dedf3bc9
2019-06-11 11:11:16 -07:00
Stephen Toub 5636b5e703 Add debug state machine tracking to GoAwayFrame_NoPendingStreams_ConnectionClosed test (dotnet/corefx#38438)
Commit migrated from https://github.com/dotnet/corefx/commit/0b0df51dab6f641e2988846dd6913de2db30789c
2019-06-10 20:22:05 -07:00
Liudmila Molkova 78938b4b54 Fix review comments in dotnet/corefx#38280 (dotnet/corefx#38406)
Commit migrated from https://github.com/dotnet/corefx/commit/6d37591d13dd58abc90b7f15b707f605e809be29
2019-06-10 19:09:37 -07:00
Liudmila Molkova 4541251707 Enable tracing context propagation without listener in presence of parent Activity (dotnet/corefx#38280)
* Enable tracing context propagation without listener in presence of parent Activity
* tests for AppContext switch


Commit migrated from https://github.com/dotnet/corefx/commit/35ebd462cc03bddc7ac135b7ec218ebd8357f7b2
2019-06-08 18:55:56 -07:00
Krzysztof Wicher a5b8971c8d HttpClient: Try decode Location header using UTF-8 (dotnet/corefx#37852)
* Use desktop logic for parsing Location (try decode using UTF-8)

* Tests and feedback

* fix netfx

* Convert UTF-8 in non-allocating way without try .. catch


Commit migrated from https://github.com/dotnet/corefx/commit/02026907370c57380a9f091b54ee77873f276a68
2019-06-07 14:38:02 -07:00
Stephen Toub b585c84595 Add debug data to help diagnose HTTP2 test failure (dotnet/corefx#38345)
The GoAwayFrame_AbortAllPendingStreams_StreamFailWithExpectedException test has been frequently hanging on some Linux distros.  This adds some diagnostics to help track it down in CI: every minute, it'll dump out the fields of the async state machine, which if nothing else will let us see which await it's stuck on and what is the state of each of the tasks.

Commit migrated from https://github.com/dotnet/corefx/commit/410a162f68eb319e8066ac7bf2d7bcd6e2ce47d0
2019-06-07 16:09:38 -04:00
Marco Rossignoli bdc76b180d Fix digest authentication on SocketsHttpHandler (dotnet/corefx#38225)
* fix digest

* improve test

* address PR feedback


Commit migrated from https://github.com/dotnet/corefx/commit/94c5f1384c9b6477d164050de964cf6dcf99b2a9
2019-06-05 11:33:31 -07:00
Martin Baulig 0b774e783c HttpClient.SendAsync() should not attempt to read response body on a HEAD or PUT request. (dotnet/corefx#38129)
* HttpClient.SendAsync() should not attempt to read response body on a HEAD or PUT request.

* Update HttpMethod.cs

* Address feedback.

* Cleanup.

* Update HttpRequestMessageTest.cs


Commit migrated from https://github.com/dotnet/corefx/commit/73e610f847f9c5100a0cec4a80692969836ff35d
2019-06-04 16:52:27 -04:00
Stephen Toub fc7622a806 Fix catch block for cancellation in ConnectHelper.ConnectAsync (dotnet/corefx#38211)
There are logic errors in ConnectHelper's catch blocks regarding cancellation.  It's catching all exceptions and then trying to decide whether it should wrap the exception in an OperationCanceledException (based on whether cancellation was requested), but it's ignoring the possibility that the exception already is an OperationCanceledException.

Commit migrated from https://github.com/dotnet/corefx/commit/80252bbc5cf2f933aef1f30d6bec7deaa3064f54
2019-06-04 16:03:25 -04:00
Stephen ToubandDavid Shulman c09abb97ba Change use of AllowRenegotiation in HttpConnectionPool (dotnet/corefx#38127)
* Change use of AllowRenegotation in HttpConnectionPool

* Address PR feedback

Fix typos in comments

Co-Authored-By: David Shulman <[email protected]>


Commit migrated from https://github.com/dotnet/corefx/commit/cada442a1385e4ecaf9139eb9f98e522776043e2
2019-06-01 15:27:50 -04:00
Tomas Weinfurt 031db203d9 add support for 100-continue for H/2 (dotnet/corefx#36884)
* expect100

* updates

* remove dead code

* fix tests

* use configured value for allowExpect100ToContinue timer

* feedback from review

* dispose expect100Timer

* feedback from review

* feedback from review

* feedback from review

* small updates to sync up with master changes

* add concurent send/recive and more tests

* fix netfx

* feedback from review

* feedback from review

* feedback from review

* feedback from review

* feedback from review

* kick ci


Commit migrated from https://github.com/dotnet/corefx/commit/b4fa2006c2e9757e4446e3fdad413bdbf265eedc
2019-05-31 14:39:12 -07:00
dotnet-maestro[bot] 10f72f160b [master] Update dependencies from dotnet/coreclr (dotnet/corefx#38099)
* Update dependencies from https://github.com/dotnet/coreclr build 20190530.2

- Microsoft.NET.Sdk.IL - 3.0.0-preview6.19280.2
- Microsoft.NETCore.ILAsm - 3.0.0-preview6.19280.2
- Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-preview6.19280.2

* Expose, test, and use Environment.TickCount64

* Back out change to WinInetProxyHelper.cs


Commit migrated from https://github.com/dotnet/corefx/commit/06f25eaa8592b49c65373d0cdcbdac9a4bdf0f35
2019-05-31 13:25:15 -07:00
Viktor Hofer b661c58b1c Replace netstandard test projects with tfms
Netstandard test projects are broken by design and don't support the
Microsoft.Net.Test.SDK. Replacing the netstandard tfm with the concrete
implementation tfms.


Commit migrated from https://github.com/dotnet/corefx/commit/d29c16c99c6045ee67444a7a693dd4476861c463
2019-05-30 16:18:41 +02:00
Tomas Weinfurt 06b43bd28e Enable MaxConnectionsPerServer_WaitingConnectionsAreCancelable again (dotnet/corefx#37933)
* enable MaxConnectionsPerServer_WaitingConnectionsAreCancelable afain

* skip with curl handler


Commit migrated from https://github.com/dotnet/corefx/commit/c6fc43c6f2b92d8e13a444217f29368159e015eb
2019-05-29 19:33:18 -07:00
Stephen Toub ec22adc0cb Remove SSL cancellation workaround from SocketsHttpHandler (dotnet/corefx#37990)
Both sockets cancellation and SslStream auth cancellation have been implemented.

Commit migrated from https://github.com/dotnet/corefx/commit/46800900077920534038be00d7bc73236e1a5fa7
2019-05-29 11:30:52 -04:00
Marco Rossignoli dbb09e4ab9 User-Agent header is ignored in "CONNECT" requests (dotnet/corefx#37785)
* flow UserAgent on CONNECT

* Apply Stephen feedback

* address PR feedback

* update test

* fix style


Commit migrated from https://github.com/dotnet/corefx/commit/1064d0352c007fd2d8fb32d7f6e286fbb6d41264
2019-05-28 09:36:25 -07:00
Tomas Weinfurt ed528dcdcb Move tests with external servers to outerloop (dotnet/corefx#37934)
* move tests with external servers to outerloop

* fix Set_ValidValues_Success


Commit migrated from https://github.com/dotnet/corefx/commit/d58a8ade31b4731759c92df00d0f6398c52f3d83
2019-05-27 14:48:04 -07:00
Viktor Hofer ba11d53cc1 Use Arcade DotNetTool and NuGetPackageRoot (dotnet/corefx#37647)
* Use Arcade props

* Use global dotnet if applicable

Commit migrated from https://github.com/dotnet/corefx/commit/f42e04b8d4be76b1818cf263ff06234d0e25ada0
2019-05-17 03:39:21 +02:00
Stephen Toub 377c37c140 Use CancellationToken.UnsafeRegister in a few more places (dotnet/corefx#37551)
CancellationToken.Register captures the current ExecutionContext and uses it to invoke the callback if/when it's invoked.  That's generally desirable and is the right default, but in cases where we know for certain the callback doesn't care about EC (e.g. we're not invoking any 3rd-party code), we can use UnsafeRegister instead (newly added in 3.0), which skips capturing the ExecutionContext, as if Capture returned null.  This helps few a couple of small costs:
- Avoids thread local lookups to capture the current EC.
- Avoids additional delegate invocations and thread local gets/sets to invoke the callback with the captured EC.
- Avoids holding on to the EC in case it's needed, which can potentially keep alive an unbounded amount of state due to AsyncLocals.

Commit migrated from https://github.com/dotnet/corefx/commit/b1a1bfa0997ce35e8540fbbe74276858e315807e
2019-05-16 11:08:10 -07:00