Uh oh!
There was an error while loading. Please reload this page.
Make sure CheckAndThrow is invoked only within ambient Cancellable context - #18037
Conversation
❗ Release notes required
|
Uh oh!
There was an error while loading. Please reload this page.
auduchinok
commented
Nov 20, 2024
Maybe it'd make sense to have this assert not in the tests only? I can imagine some FCS APIs that may trigger analysis and that don't take a cancellation token. If there're no tests for such APIs, it's going to be very difficult to uncover these, as they'd only manifest themself when cancelled at some unfortunate moment. The sooner we catch all these exceptions, the better. Maybe we could have some global property or other way to control it. With this way we'd enable these asserts in the internal and EAP Rider builds, but could turn it off just in case in the release ones, at least for the time being. |
majocha
commented
Nov 20, 2024
TBH my initial thought was to just put a hard |
majocha
commented
Nov 21, 2024
Added DISABLE_CHECKANDTHROW_ASSERT env variable that can be set in case of emergencies. |
psfinaki
commented
Nov 25, 2024
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
psfinaki
commented
Nov 25, 2024
@majocha do I get it right that the TODO in the description is already done? |
majocha
commented
Nov 25, 2024
Yes, forgot to edit this. |
See: #18002 (comment)
Basically, when
Cancelable.CheckAndThrow()throws the exception, we don't want the exception to leak.It should be caught inside
Cancellable.runhere:fsharp/src/Compiler/Utilities/Cancellable.fs
Lines 44 to 52 in e44ae1d
The idea of
CheckAndThrowis that it is invoked from code that is unaware ofCancellableCE somewhere deeper on the callstack.This PR checks the static
AsyncLocal<CancellationToken voption>token. If it is default VNone, we know the invocation is outside of Cancellable. If there is a token present, we knowCancellable.rundeeper on the stack has set it and we're good.With this PR, internal error will occur whenever
CheckAndThrowis called outside of Cancellable CE context.