coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.94k stars 385 forks source link

Coverlet shouldn't crash dotnet.exe if it can't restore instrumented binary after the run #1197

Open KirillOsenkov opened 2 years ago

KirillOsenkov commented 2 years ago

I'm seeing dotnet.exe crashes when Coverlet is trying to modify the test .dll on disk and it's locked (by a debugger or antivirus).

>   KERNELBASE.dll!RaiseException(unsigned long dwExceptionCode, unsigned long dwExceptionFlags, unsigned long nNumberOfArguments, const unsigned __int64 * lpArguments) Line 940   C
    [Managed to Native Transition]  
    coverlet.core.dll!Coverlet.Core.Helpers.RetryHelper.Do<System.__Canon>(System.Func<System.__Canon> action, System.Func<System.TimeSpan> backoffStrategy, int maxAttemptCount) Line 59   C#
    coverlet.core.dll!Coverlet.Core.Helpers.RetryHelper.Retry(System.Action action, System.Func<System.TimeSpan> backoffStrategy, int maxAttemptCount) Line 28  C#
    coverlet.core.dll!Coverlet.Core.Helpers.InstrumentationHelper.RestoreOriginalModules() Line 248 C#
    coverlet.core.dll!Coverlet.Core.Helpers.InstrumentationHelper..ctor.AnonymousMethod__6_0(object s, System.EventArgs e) Line 27  C#
    System.Private.CoreLib.dll!System.AppContext.OnProcessExit() Line 77    C#
    [Native to Managed Transition]  
    kernel32.dll!BaseThreadInitThunk(unsigned long RunProcessInit, long(*)(void *) StartAddress, void * Argument) Line 64   C
    ntdll.dll!RtlUserThreadStart(long(*)(void *) StartAddress, void * Argument) Line 1153   C

It should report the error and continue, but not tear down the entire dotnet.exe process.

KirillOsenkov commented 2 years ago

There should be a catch block in RestoreOriginalModules() since the Retry can throw

MarcoRossignoli commented 2 years ago

Thanks for reporting this!