Suggestion: introduce timeout to back up the assumptions about cancellation callback performance.
@stephentoub @geoffkizer
https://github.com/dotnet/coreclr/blob/5699a504640a322935f7f57f3ea627cee494c804/src/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs#L738
Per https://github.com/dotnet/corefx/issues/32262 issue infinite loops are dangerous for an unsuspecting API consumer like class HttpConnectionPool.
If the spin https://github.com/dotnet/coreclr/blob/5699a504640a322935f7f57f3ea627cee494c804/src/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs#L736 cannot be avoided then a reasonable timeout crashing the runtime may be a better outcome than a lingering deadlock.
@tarekgh
then a reasonable timeout crashing the runtime may be a better outcome than a lingering deadlock
What is "reasonable"? There's no value we could pick that wouldn't break some valid use case. I understand your concerns, and I don't believe we should do anything here.
@stephentoub @karelz
What is "reasonable"? There's no value we could pick that wouldn't break some valid use case. I understand your concerns, and I don't believe we should do anything here.
We could've just been extremely unlucky, but this is the second time (see the first instance) we have run into the problem in our production system due to CancellationTokenSource.WaitForCallbackToComplete logic causing the deadlock within the dotnet own code.
If the expectation is that no-one should be employing synchronization logic when using TPL and the only thing that is missing is a better, transparent documentation.
@stephentoub
After some more research on the subject, the proposal in https://github.com/dotnet/corefx/issues/14903 should be able to address the issue in the future. Right?
Right?
Yes, that's already been implemented. If you don't want to wait for the callback to complete, you can call Unregister instead of or before Dispose.
@stephentoub Closing the issue due to dotnet/corefx#14903. Thank you.