fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Fix some possibly buggy usage of `UseDiagnosticsLogger`

Open majocha opened this issue 4 months ago • 2 comments

Description

There was some odd behavior I noticed while trying to test AsyncLocal diagnostics state. UseDiagnosticsLogger creates a diagnostics scope and should restore previous logger on dispose. This should in theory work consistently, pushing and unwinding loggers in the given order. I noticed the disposals often happen out of order, leading to momentarily inconsistent state.

By chance I stumbled upon what I believ are some slight bugs in ParseAndCheckInputs.fs:

https://github.com/dotnet/fsharp/blob/3ec9b18de99808756ea1c577dfc0465b9d219408/src/Compiler/Driver/ParseAndCheckInputs.fs#L1390-L1401 This function returns a cancellable, so the disposables will get disposed immediately instead of participating in the cancellable execution.

Similar situation here: https://github.com/dotnet/fsharp/blob/3ec9b18de99808756ea1c577dfc0465b9d219408/src/Compiler/Driver/ParseAndCheckInputs.fs#L1857-L1881

Disposal happens immediately, leaving us with other global diagnostic logger than expected.

Let's see if fixing this breaks something else.

majocha avatar Feb 23 '24 10:02 majocha

:warning: Release notes required, but author opted out

[!WARNING] Author opted out of release notes, check is disabled for this pull request. cc @dotnet/fsharp-team-msft

github-actions[bot] avatar Feb 23 '24 10:02 github-actions[bot]

This is only tangentially related, but I replaced the instances where we don't intend to ever unwind:

let _holder = UseDiagnosticsLogger diagnosticsLogger

with

SetThreadDiagnosticsLoggerNoUnwind diagnosticsLogger

which does not allocate a disposable and makes it easier to later test for correct order of unwinds.

majocha avatar Feb 23 '24 11:02 majocha

/azp run

psfinaki avatar Feb 26 '24 11:02 psfinaki

Azure Pipelines successfully started running 2 pipeline(s).

azure-pipelines[bot] avatar Feb 26 '24 11:02 azure-pipelines[bot]