Repository navigation
Fix NullReferenceException in reportTime when compilations run concurrently - #20974
Conversation
…d NRE during concurrent use Closes: dotnet#20973
✅ Release notes checked
|
|
@dotnet-policy-service agree |
abonie
left a comment
There was a problem hiding this comment.
🤖🕵️ AI review — verify independently.
|
Is it possible to get rid of the global mutable instead of locking? |
|
Anything is possible, I just kept it intentionally point-fixing because 1) it's my first PR here 2) my F# skill is a WIP and 3) I saw the handling elsewhere (e.g. CompilerOptions.ReportTime) wasn't remarkably different (a global mutable there too). I'll look this afternoon for a way to remove the global mutable entirely. |
|
@majocha do you know how tied we are to these stage labels passed to use _ = Activity.Profiling.startAndMeasureEnvironmentStats "<the stage label>"I was going to start attempting this but then I realized - I think the current GenTypeDefsPass1 [] cenv tdefs
reportTime "Module Generation Pass 1"
GenTypeDefsPass2 0 [] cenv tdefs
reportTime "Module Generation Pass 2"But that doesn't jive with what Looking back, I found this commit changed So I think that should be fixed, and if I adjust the calls to be scoped with a |
Yeah, this does not look right. This is clearly error prone and confusing. Instead of global mutable I'd add some wrapper type holding the current activity, create an instance at the topmost call ( |
Okay, working on that. |
949fb9b to
cd037b7
Compare
This is now done as you described with a new type |
Description
reportTimeinsrc/Compiler/Utilities/illib.fskeeps the current profiling activity in a process-wide mutable,tPrev. When two compilations write IL at the same time and anActivityListenersamplesfsc_with_env_stats, one thread can nulltPrevbetween another thread's null check and itsDispose, which surfaces asFS0193: internal error: Object reference not set to an instance of an object.This takes a lock around disposing the previous activity and storing the next, so the check and the dereference can no longer interleave with another thread.This only stops the NRE.Revised: replaced global mutable (and the lock this PR initially added) with a locally-allocated timer object being passed down to each timed section.
There is still one process-wide slot, so concurrent compilations still mix each other's phase timings, as
ReportTimeinCompilerOptions.fsalready does. Making the timing per compilation would be a larger change and is left out of this PR.Fixes #20973
Checklist