postsharp / Metalama

Metalama is a Roslyn-based meta-programming framework. Use this repo to report bugs or ask questions.
176 stars 5 forks source link

Bug report: Cannot create a file when that file already exists #177

Closed WhitWaldo closed 1 year ago

WhitWaldo commented 1 year ago

I received an error on my build server today (running Windows Server 2019 Datacenter edition in Azure) on the latest preview build as follows:

[error]CSC(0,0): Error LAMA0001: Unexpected exception occurred in Metalama: Cannot create a file when that file already exists. Exception details are in 'C:\windows\ServiceProfiles\NetworkService\AppData\Local\Temp\Metalama\CrashReports\2023.2.1-preview\exception-98783161-ec5a-4f86-838b-f282f5973da5.txt'.

And here's the crash report itself:

Metalama Version: 2023.2.1-preview Runtime: .NET 6.0.16 Processor Architecture: X64 OS Description: Microsoft Windows 10.0.17763 OS Architecture: X64 Exception type: System.IO.IOException Exception message: Cannot create a file when that file already exists. ===== Exception ===== System.IO.IOException: Cannot create a file when that file already exists. at System.IO.FileSystem.MoveFile(String sourceFullPath, String destFullPath, Boolean overwrite) at System.IO.File.Move(String sourceFileName, String destFileName, Boolean overwrite) at System.IO.File.Move(String sourceFileName, String destFileName) at Metalama.Framework.Engine.CompileTime.CompileTimeCompilationBuilder.<>cDisplayClass24_1.b_1(String ) at Metalama.Backstage.Utilities.RetryHelper.<>cDisplayClass2_1.b1() at Metalama.Backstage.Utilities.RetryHelper.<>cDisplayClass0_0.b0() at Metalama.Backstage.Utilities.RetryHelper.Retry[T](Func1 action, Predicate1 retryPredicate, ILogger logger, Action1 onException) at Metalama.Backstage.Utilities.RetryHelper.Retry(Action action, Predicate1 retryPredicate, ILogger logger, Action`1 onException) at Metalama.Backstage.Utilities.RetryHelper.<>cDisplayClass2_0.b__0() at Metalama.Backstage.Utilities.RetryHelper.ExecuteWithLockDetection(Action action, DeadlockDetectionContext context) at Metalama.Framework.Engine.CompileTime.CompileTimeCompilationBuilder.TryEmit(OutputPaths outputPaths, Compilation compileTimeCompilation, IDiagnosticAdder diagnosticSink, TextMapDirectory textMapDirectory, CancellationToken cancellationToken) at Metalama.Framework.Engine.CompileTime.CompileTimeCompilationBuilder.TryGetCompileTimeProjectImpl(ClassifyingCompilationContext compilationContext, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList1 sourceTreesWithCompileTimeCode, IReadOnlyList1 referencedProjects, ImmutableArray1 globalUsings, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CompileTimeProject& project, CancellationToken cancellationToken) at Metalama.Framework.Engine.CompileTime.CompileTimeCompilationBuilder.TryGetCompileTimeProject(ClassifyingCompilationContext compilationContext, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList1 compileTimeTreesHint, IReadOnlyList1 referencedProjects, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CompileTimeProject& project, CancellationToken cancellationToken) at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryGetCompileTimeProjectFromCompilation(ClassifyingCompilationContext compilationContext, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList1 compileTimeTreesHint, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProject& compileTimeProject) at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Builder.TryBuild(Compilation compilation, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList1 compileTimeTreesHint, IDiagnosticAdder diagnosticSink, Boolean cacheOnly, CancellationToken cancellationToken, CompileTimeProjectRepository& loader) at Metalama.Framework.Engine.CompileTime.CompileTimeProjectRepository.Create(CompileTimeDomain domain, ProjectServiceProvider serviceProvider, Compilation compilation, IDiagnosticAdder diagnostics, Boolean cacheOnly, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList1 compileTimeTreesHint, CancellationToken cancellationToken) at Metalama.Framework.Engine.Pipeline.AspectPipeline.TryInitialize(IDiagnosticAdder diagnosticAdder, Compilation compilation, ProjectLicenseInfo projectLicenseInfo, IReadOnlyList1 compileTimeTreesHint, CancellationToken cancellationToken, AspectPipelineConfiguration& configuration) at Metalama.Framework.Engine.Pipeline.CompileTime.CompileTimeAspectPipeline.ExecuteAsync(IDiagnosticAdder diagnosticAdder, Compilation compilation, ImmutableArray1 resources, TestableCancellationToken cancellationToken)

The same project builds fine on my local dev box (Windows 10, x64) without issue.

PostSharpBot commented 1 year ago

Hello @WhitWaldo, thank you for submitting this issue. We will try to get back to you as soon as possible. Note to the PostSharp team, this ticket is being tracked in our dashboard under ID TP-33464.

WhitWaldo commented 1 year ago

Following up, this is a regression as the build works without issue when I roll back to v2023.1.9.

prochan2 commented 1 year ago

Hello @WhitWaldo , may I ask you to collect logs of this behavior as described at https://doc.metalama.net/conceptual/configuration/creating-logs and send us the logs?

In the logs, you should also see which file is causing this. Please try to delete the file to unblock the failing build.

WhitWaldo commented 1 year ago

Hello @prochan2 - are those instructions valid for a build server as well where there is no active and running IDE instance?

gfraiteur commented 1 year ago

I think no log will be needed.

It's probably not a regression but a random race so cleaning the temp directory and retrying should be ok.

svick commented 1 year ago

This should be fixed in Metalama 2023.2.2-rc.

WhitWaldo commented 1 year ago

Experienced this again on the build server after migrating to 2023.3.4-preview while building a solution with nothing but a TransitiveProjectFabric in it. Deleting the file works right up until the next time it builds.

Resolved it by adding a clean step to the workspace job so it always starts the build with a clean directory, but it means the underlying issue hasn't been resolved. Again, no idea why this is only an issue on the build server and never locally.

gfraiteur commented 1 year ago

I got the same issue internally so I'm reopening the ticket.

gfraiteur commented 1 year ago

This, hopefully, has been solved in 2023.3 rc.