runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Suggestion: introduce timeout to back up the assumptions about cancellation callback performance.

Open baal2000 opened this issue 8 years ago • 6 comments

@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.

baal2000 avatar Sep 13 '18 12:09 baal2000

@tarekgh

kouvel avatar Sep 13 '18 16:09 kouvel

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 avatar Sep 24 '18 21:09 stephentoub

@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.

baal2000 avatar Sep 24 '18 23:09 baal2000

@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?

baal2000 avatar Sep 24 '18 23:09 baal2000

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 avatar Sep 25 '18 00:09 stephentoub

@stephentoub Closing the issue due to dotnet/corefx#14903. Thank you.

baal2000 avatar Sep 25 '18 00:09 baal2000