Repository navigation
Labels
Milestone
Description
System.Exception: Token not available outside of Cancellable computation.
at <StartupCode$FSharp-Compiler-Service>.$Cancellable.defThunk@1(String msg, Unit unitVar0) in C:\Developer\jetbrains-fsharp\src\Compiler\Utilities\Cancellable.fs:line 15
at FSharp.Compiler.Cancellable.ensureToken(String msg) in C:\Developer\jetbrains-fsharp\src\Compiler\Utilities\Cancellable.fs:line 14
at FSharp.Compiler.Cancellable.get_Token() in C:\Developer\jetbrains-fsharp\src\Compiler\Utilities\Cancellable.fs:line 19
at JetBrains.ReSharper.Plugins.FSharp.FSharpAsyncUtil.UsingReadLockInsideFcs(IShellLocks locks, Action action, Func`1 upToDateCheck) in C:\Developer\resharper-fsharp\ReSharper.FSharp\src\FSharp\FSharp.ProjectModelBase\src\FSharpAsyncUtil.cs:line 40
at JetBrains.ReSharper.Plugins.FSharp.Shim.AssemblyReader.ProjectFcsModuleReader.readData(FSharpFunc`2 f) in C:\Developer\resharper-fsharp\ReSharper.FSharp\src\FSharp\FSharp.Common\src\Shim\AssemblyReader\ProjectFcsModuleReader.fs:line 142
at JetBrains.ReSharper.Plugins.FSharp.Shim.AssemblyReader.ProjectFcsModuleReader.FSharp.Compiler.AbstractIL.ILBinaryReader.ILModuleReader.get_ILModuleDef() in C:\Developer\resharper-fsharp\ReSharper.FSharp\src\FSharp\FSharp.Common\src\Shim\AssemblyReader\ProjectFcsModuleReader.fs:line 1358
at FSharp.Compiler.CompilerImports.TcImports.OpenILBinaryModule(CompilationThreadToken ctok, String fileName, Range m) in C:\Developer\jetbrains-fsharp\src\Compiler\Driver\CompilerImports.fs:line 1635
And this is the stack from the debugger:
$Cancellable.defThunk@1() at C:/Developer/jetbrains-fsharp/src/Compiler/Utilities/Cancellable.fs:line 15
Cancellable.ensureToken() at C:/Developer/jetbrains-fsharp/src/Compiler/Utilities/Cancellable.fs:line 14
Cancellable.get_Token()
FSharpAsyncUtil.UsingReadLockInsideFcs()
ProjectFcsModuleReader.readData()
ProjectFcsModuleReader.FSharp.Compiler.AbstractIL.ILBinaryReader.ILModuleReader.get_ILModuleDef()
CompilerImports.TcImports.OpenILBinaryModule()
CompilerImports.TryRegisterAndPrepareToImportReferencedDll@2265-3.Invoke()
AsyncPrimitives.CallThenInvokeNoHijackCheck<Microsoft.FSharp.Core.FSharpOption<System.Tuple<FSharp.Compiler.CompilerImports.ImportedBinary, Microsoft.FSharp.Core.FSharpFunc<Microsoft.FSharp.Core.Unit, Microsoft.FSharp.Collections.FSharpList<FSharp.Compiler.CompilerImports.AvailableImportedAssembly>>>>, FSharp.Compiler.CompilerConfig.ProjectAssemblyDataResult>()
Trampoline.Execute()
$Async.clo@193-15.Invoke()
QueueUserWorkItemCallback.WaitCallback_Context()
ExecutionContext.RunInternal()
ExecutionContext.Run()
QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
ThreadPoolWorkQueue.Dispatch()
_ThreadPoolWaitCallback.PerformWaitCallback()
[Native to Managed Transition]
[Application Domain Transition]
[Native to Managed Transition]
@majocha Could that be of interest for you? 🙂
Reacted by Jakub Majocha
Reacted by Jakub Majocha
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
Activity
majocha commentedon Jan 14, 2025
Just from reading the code I guess the problem is here
fsharp/src/Compiler/Driver/CompilerImports.fs
Lines 2251 to 2257 in b2f2065
Despite what the comment says, this is
async, notcancellableTo propagate the cancellation token the call to
ILModuleDefgetter must be wrapped incancellablesomewhere in between. I suspect that's what's causing the problem.majocha commentedon Jan 14, 2025
Yes, the thing is,
ILModuleReadercontract does not suggest cancellability in any way.fsharp/src/Compiler/AbstractIL/ilread.fsi
Lines 62 to 66 in b2f2065
auduchinok commentedon Jan 14, 2025
Hm, but there are many APIs that aren't themself aware of possible cancellations, and it's fine. What's important is their calls are wrapped in the cancellable computation somewhere.
majocha commentedon Jan 14, 2025
True, but relying on convention over explicit type contract in public api makes me feel uneasy 😄.
I looked through the code and I can see a few other potentially problematic places where
ILModuleReaderis used with no cancellable in sight.auduchinok commentedon Jan 14, 2025
True, but I also think we don't want to change the entire IL subsystem to annotate everything as cancellable explicitly.
My rule of thumb would probably be something like "everything during an analysis phase is wrapped into a cancellable computation somewhere" 🙂
majocha commentedon Jan 14, 2025
Makes sense :) I'm wondering what to wrap in cancellable to make a reasonably seamless fix.
T-Gro commentedon Jan 15, 2025
Could we treat everything async around CompilerImports as being a cancellable?
I guess that would require shadowing
asyncwith something different, making it somewhat obfuscated to those unaware.. :(majocha commentedon Jan 15, 2025
We could maybe use some resumable AsyncEx flavor internally throughout and only keep legacy async on public endpoints.