Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Diagnostics.Tests.ProcessModuleTests.ModulesAreDisposedWhenProcessIsDisposed test is failing #68035

Closed
ViktorHofer opened this issue Apr 14, 2022 · 3 comments · Fixed by #68104

Comments

@ViktorHofer
Copy link
Member

Build: https://dnceng.visualstudio.com/public/_build/results?buildId=1711437&view=ms.vss-test-web.build-test-results-tab&runId=46535502&resultId=129201&paneView=dotnet-dnceng.dnceng-build-release-tasks.helix-test-information-tab

Configuration: net7.0-windows-Release-x86-CoreCLR_release-Windows.7.Amd64.Open

  Discovering: System.Diagnostics.Process.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Diagnostics.Process.Tests (found 258 of 281 test cases)
  Starting:    System.Diagnostics.Process.Tests (parallel test collections = on, max threads = 2)
    System.Diagnostics.Tests.ProcessModuleTests.ModulesAreDisposedWhenProcessIsDisposed [FAIL]
      System.ComponentModel.Win32Exception : Only part of a ReadProcessMemory or WriteProcessMemory request was completed.
      Stack Trace:
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs(239,0): at System.Diagnostics.NtProcessManager.EnumProcessModulesUntilSuccess(SafeProcessHandle processHandle, IntPtr[] modules, Int32 size, Int32& needed)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs(111,0): at System.Diagnostics.NtProcessManager.GetModules(Int32 processId, Boolean firstModuleOnly)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs(380,0): at System.Diagnostics.NtProcessManager.GetModules(Int32 processId)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs(165,0): at System.Diagnostics.ProcessManager.GetModules(Int32 processId)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs(315,0): at System.Diagnostics.Process.get_Modules()
        /_/src/libraries/System.Diagnostics.Process/tests/ProcessModuleTests.cs(79,0): at System.Diagnostics.Tests.ProcessModuleTests.ModulesAreDisposedWhenProcessIsDisposed()
           at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
        /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs(379,0): at System.Reflection.RuntimeMethodInfo.InvokeNonEmitUnsafe(Object obj, IntPtr* arguments, Span`1 argsForTemporaryMonoSupport, BindingFlags invokeAttr)
    System.Diagnostics.Tests.ProcessStartInfoTests.ShellExecute_Nano_Fails_Start [SKIP]
      Condition(s) not met: "IsWindowsNanoServer"
Invalid number of parameters
0 File(s) copied
  Finished:    System.Diagnostics.Process.Tests
=== TEST EXECUTION SUMMARY ===
   System.Diagnostics.Process.Tests  Total: 318, Errors: 0, Failed: 1, Skipped: 1, Time: 33.721s
@ghost
Copy link

ghost commented Apr 14, 2022

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

Issue Details

Build: https://dnceng.visualstudio.com/public/_build/results?buildId=1711437&view=ms.vss-test-web.build-test-results-tab&runId=46535502&resultId=129201&paneView=dotnet-dnceng.dnceng-build-release-tasks.helix-test-information-tab

Configuration: net7.0-windows-Release-x86-CoreCLR_release-Windows.7.Amd64.Open

  Discovering: System.Diagnostics.Process.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Diagnostics.Process.Tests (found 258 of 281 test cases)
  Starting:    System.Diagnostics.Process.Tests (parallel test collections = on, max threads = 2)
    System.Diagnostics.Tests.ProcessModuleTests.ModulesAreDisposedWhenProcessIsDisposed [FAIL]
      System.ComponentModel.Win32Exception : Only part of a ReadProcessMemory or WriteProcessMemory request was completed.
      Stack Trace:
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs(239,0): at System.Diagnostics.NtProcessManager.EnumProcessModulesUntilSuccess(SafeProcessHandle processHandle, IntPtr[] modules, Int32 size, Int32& needed)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs(111,0): at System.Diagnostics.NtProcessManager.GetModules(Int32 processId, Boolean firstModuleOnly)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs(380,0): at System.Diagnostics.NtProcessManager.GetModules(Int32 processId)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs(165,0): at System.Diagnostics.ProcessManager.GetModules(Int32 processId)
        /_/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs(315,0): at System.Diagnostics.Process.get_Modules()
        /_/src/libraries/System.Diagnostics.Process/tests/ProcessModuleTests.cs(79,0): at System.Diagnostics.Tests.ProcessModuleTests.ModulesAreDisposedWhenProcessIsDisposed()
           at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
        /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.CoreCLR.cs(379,0): at System.Reflection.RuntimeMethodInfo.InvokeNonEmitUnsafe(Object obj, IntPtr* arguments, Span`1 argsForTemporaryMonoSupport, BindingFlags invokeAttr)
    System.Diagnostics.Tests.ProcessStartInfoTests.ShellExecute_Nano_Fails_Start [SKIP]
      Condition(s) not met: "IsWindowsNanoServer"
Invalid number of parameters
0 File(s) copied
  Finished:    System.Diagnostics.Process.Tests
=== TEST EXECUTION SUMMARY ===
   System.Diagnostics.Process.Tests  Total: 318, Errors: 0, Failed: 1, Skipped: 1, Time: 33.721s
Author: ViktorHofer
Assignees: -
Labels:

area-System.Diagnostics.Process

Milestone: -

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Apr 14, 2022
@danmoseley
Copy link
Member

// When called on a running process, EnumProcessModules may fail with ERROR_PARTIAL_COPY
// if the target process is not yet initialized or if the module list changes during the function call.
// We just try to avoid the race by retring 50 (an arbitrary number) times.
int i = 0;
while (true)

here's a little more context from the .NET Framework code:

                        // Also, EnumProcessModules is not a reliable method to get the modules for a process. 
                        // If OS loader is touching module information, this method might fail and copy part of the data.
                        // This is no easy solution to this problem. The only reliable way to fix this is to 
                        // suspend all the threads in target process. Of course we don't want to do this in Process class.
                        // So we just to try avoid the race by calling the same method 50 (an arbitary number) times.

Options - increase the 50 to 100 (it's a failure mode anyway); or change ModulesAreDisposedWhenProcessIsDisposed to retry.

@danmoseley
Copy link
Member

In the last 2 months, this has failed 2x , both Windows 7 x86, but of none of the other tests that get .Modules have failed. Significantly this is the only one of them that doesn't invoke it on an existing process (the current process).

Is there an issue with the process not fully starting? There is a 50ms loop above, but perhaps not always enough. Looking back in history, there was an attempt presumably this issue with a spin wait in such a test. But when it failed with this error, it was replaced with a test using the current process.
https://github.com/dotnet/corefx/pull/2513/files#diff-14dbdde3b088685d2565e5694279a5fd52d762d8172ec4609cdf2f58bafefe99L201

With this evidence, a change to the product seems like a hack. I will just add a retry on this test.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Apr 16, 2022
@ghost ghost removed untriaged New issue has not been triaged by the area owner in-pr There is an active PR which will close this issue when it is merged labels Apr 20, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants