Uh oh!
There was an error while loading. Please reload this page.
Test NodeCode - #16576
Conversation
|
vzarytovskii
commented
Jan 23, 2024
FWIW, I am currently getting rid of node code and replacing it with cancellable tasks, thread static preservation is something I've baked into state machine. But it's far from being finished. |
0101
commented
Jan 24, 2024
Good idea to test this. It definitely looks concerning. I'm surprised it didn't cause us any issues this whole time 🤔 |
Uh oh!
There was an error while loading. Please reload this page.
majocha
commented
Jan 24, 2024
I think Threadpool mostly queues continuations on the same thread unless really pushed and our stuff is quite sequential. NodeCode.Parallel was added just recently with the graph-based type checking. |
0101
commented
Jan 24, 2024
Does this reproduce with anything else than And it was actually used before in But maybe those places don't need the thread statics. |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Petr Pokorny <petr@innit.cz>
vzarytovskii
commented
Jan 24, 2024
Nothing regarding changes in this code, but all the thread static management becomes more and more convoluted. It's really hard to follow-up what's actually going on. |
majocha
commented
Jan 24, 2024
Works now, although I dislike passing state with Do we need release notes for this PR? |
Uh oh!
There was an error while loading. Please reload this page.
0101
commented
Jan 24, 2024
I think we don't need release notes for this. It doesn't affect the users. |
0101
commented
Jan 25, 2024
Hmm, now with this already merged and built into VSIX, I started seeing: System.AggregateException : One or more errors occurred. ---> Object reference not set to an instance ofanobject.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions.CheckerExtensions.FSharpChecker-ParseAndCheckDocumentUsingTransparentCompiler@355(<Unknown Parameters>)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions.CheckerExtensions.FSharpChecker-ParseAndCheckDocument@448(<Unknown Parameters>)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions.Document-GetFSharpParseAndCheckResultsAsync@538(<Unknown Parameters>)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async StartupCode$FSharp-Editor(<Unknown Parameters>)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.<>c__DisplayClass12_0.<GetRefactoringFromProviderAsync>b__0(<Unknown Parameters>)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)--->(Inner Exception #0) System.NullReferenceException : Object reference not set to an instance ofanobject.
at Internal.Utilities.Collections.Utils.replayDiagnostics@31.Invoke(Tuple`2 arg1)
at Microsoft.FSharp.Collections.SeqModule.Iterate[T](FSharpFunc`2 action,IEnumerable`1 source)
at Internal.Utilities.Collections.Utils.replayDiagnostics@31-1.Invoke(IEnumerable`1 source)
at async StartupCode$FSharp-Compiler-Service[TKey,TVersion,TValue,d](<Unknown Parameters>)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async StartupCode$FSharp-Compiler-Service[a,b](<Unknown Parameters>)<---I can't quite explain it, even if somehow there was no logger set on a thread, we should still get |
majocha
commented
Jan 25, 2024
ResizeArray is not threadsafe? |
0101
commented
Jan 25, 2024
True, but access to it is always under lock, unless I missed something. Also can it throw NRE due to a race condition? |
majocha
commented
Jan 25, 2024
Yes, right. There is a lock. We supposedly always initialize the static field to AssertFalseDiagnosticsLogger. That's wierd. |
majocha
commented
Jan 25, 2024
So I'd look at places when we call the setter. Lots of them. |
0101
commented
Jan 25, 2024
Well it seems to have been caused by this PR. I haven't seen it before. Wonder if we somehow depended on the incorrect behavior before. |
majocha
commented
Jan 26, 2024
Now I've seen the exact exception, too, surfacing in VS. But I haven't found a way to reproduce it. |
0101
commented
Jan 26, 2024
Yeah a reliable repro would be nice, but not sure it's even possible. I've tried to get it in debug but couldn't so far. |
majocha
commented
Jan 29, 2024
I'm very sure your code is good. |
| computations | ||
| |> Seq.map (fun (Node x) -> | ||
| async { | ||
| DiagnosticsThreadStatics.DiagnosticsLogger <- diagnosticsLogger |
There was a problem hiding this comment.
This is not safe, as the logger we're passing is most probably not thread-safe. So we're betting on the computation to actually never use it.
majocha
commented
Feb 14, 2024
@0101 I suspect we cannot pass a non-thread safe logger here: fsharp/src/Compiler/Facilities/BuildGraph.fs Lines 199 to 208 in 37251d4 We're betting on the computation to actually never use it. I guess in some tasks it does use it causing mayhem. |
0101
commented
Feb 14, 2024
Yeah you're right. We should either make it a thread-safe one or pass a separate one to each computation and then merge the results. |
majocha
commented
Feb 14, 2024
Yes, I think I had something like this in the AsyncLocal branch. |
I had a hunch something's not right with
NodeCode:#16536 (comment)
I suspect with increased parallelization brought by Transparent Compiler it tends to mangle thread statics it's supposed to preserve (?)
So, this is a failing test.