diff --git a/NuGet.config b/NuGet.config index a6df74bb15e..7bc9d52549b 100644 --- a/NuGet.config +++ b/NuGet.config @@ -23,6 +23,8 @@ + + diff --git a/azure-pipelines-PR.yml b/azure-pipelines-PR.yml index 18d1c38f3bd..95927d469d0 100644 --- a/azure-pipelines-PR.yml +++ b/azure-pipelines-PR.yml @@ -496,8 +496,13 @@ stages: - script: ./eng/common/dotnet.sh fsi tests/EndToEndBuildTests/MultithreadedTasks/run.fsx -- --configuration $(_BuildConfig) --repetitions 3 displayName: Real SDK MP / MT integration condition: and(succeeded(), eq(variables['batchNumber'], '1')) - - task: PublishPipelineArtifact@1 + - pwsh: | + $exists = Test-Path -LiteralPath "$(Build.SourcesDirectory)/artifacts/MultithreadedTasks" -PathType Container + Write-Host "##vso[task.setvariable variable=SdkMtEvidenceAvailable]$exists" + displayName: Check SDK MT evidence condition: and(always(), eq(variables['batchNumber'], '1')) + - task: PublishPipelineArtifact@1 + condition: and(always(), eq(variables['batchNumber'], '1'), eq(variables['SdkMtEvidenceAvailable'], 'true')) inputs: targetPath: '$(Build.SourcesDirectory)/artifacts/MultithreadedTasks' artifact: Linux SDK MT evidence @@ -544,8 +549,13 @@ stages: displayName: End to end build tests - script: .\eng\common\dotnet.cmd fsi tests\EndToEndBuildTests\MultithreadedTasks\run.fsx -- --configuration Release --repetitions 3 displayName: Real SDK MP / MT integration - - task: PublishPipelineArtifact@1 + - pwsh: | + $exists = Test-Path -LiteralPath "$(Build.SourcesDirectory)/artifacts/MultithreadedTasks" -PathType Container + Write-Host "##vso[task.setvariable variable=SdkMtEvidenceAvailable]$exists" + displayName: Check SDK MT evidence condition: always() + - task: PublishPipelineArtifact@1 + condition: and(always(), eq(variables['SdkMtEvidenceAvailable'], 'true')) inputs: targetPath: '$(Build.SourcesDirectory)/artifacts/MultithreadedTasks' artifact: Windows SDK MT evidence diff --git a/eng/Build.ps1 b/eng/Build.ps1 index d7053f7da5a..f6445c290e9 100644 --- a/eng/Build.ps1 +++ b/eng/Build.ps1 @@ -82,11 +82,6 @@ param ( Set-StrictMode -version 2.0 $ErrorActionPreference = "Stop" -# MSBuild's multi-threaded mode isn't run on CI unless it was explicitly requested via -msbuildMultiThreaded. -# tools.ps1 reads $msbuildMultiThreaded, so this has to be settled before Arcade is imported. -if ($ci -and -not $PSBoundParameters.ContainsKey('msbuildMultiThreaded')) { - $msbuildMultiThreaded = $false -} $BuildCategory = "" $BuildMessage = "" diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index c2e7b96c6f2..6c812a02fcc 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -1,6 +1,6 @@ - + https://github.com/dotnet/msbuild diff --git a/src/Compiler/Facilities/AsyncMemoize.fs b/src/Compiler/Facilities/AsyncMemoize.fs index 16f4787209d..cc652c24f90 100644 --- a/src/Compiler/Facilities/AsyncMemoize.fs +++ b/src/Compiler/Facilities/AsyncMemoize.fs @@ -93,8 +93,11 @@ type AsyncLazy<'t> private (initial: AsyncLazyState<'t>, cancelUnawaited: bool, member _.Request() = async { + // Register before try/finally, whose cleanup runs even when cancellation skips its body. + let computation = withStateUpdate request + try - return! withStateUpdate request + return! computation finally updateState afterRequest } diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerService/AsyncMemoize.fs b/tests/FSharp.Compiler.ComponentTests/CompilerService/AsyncMemoize.fs index bb8ab98d839..497098aa5c9 100644 --- a/tests/FSharp.Compiler.ComponentTests/CompilerService/AsyncMemoize.fs +++ b/tests/FSharp.Compiler.ComponentTests/CompilerService/AsyncMemoize.fs @@ -283,6 +283,36 @@ let ``Job keeps running if only one requestor cancels`` () : Task = Finished, key ] } +[] +let ``Job keeps running when requests cancel before attaching`` () : Task = + task { + use jobStarted = new ManualResetEvent(false) + use jobCanComplete = new ManualResetEvent(false) + + let computation = async { + jobStarted.Set() |> ignore + do! awaitHandle jobCanComplete + return 42 + } + + let memoize = AsyncMemoize<_, int, _>() + let request = memoize.Get(wrapKey 1, computation) + let survivor = Async.StartAsTask request + + do! awaitHandle jobStarted + + for delay in 0 .. 9999 do + use cts = new CancellationTokenSource() + let other = Async.StartAsTask(request, cancellationToken = cts.Token) + Thread.SpinWait (delay % 1000) + cts.Cancel() + do! assertTaskCanceled other + + jobCanComplete.Set() |> ignore + let! result = survivor + Assert.Equal(42, result) + } + type ExpectedException() = inherit Exception()