You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "jbliznak (via GitHub)" <gi...@apache.org> on 2026/02/07 23:51:58 UTC

[PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

jbliznak opened a new pull request, #3258:
URL: https://github.com/apache/maven-surefire/pull/3258

   fix for #3176 
   
   WMIC is not available in recent Windows versions.
   The new solution with PowerShell should work for Windows 8 and newer
   and Windows Server 2012 and newer.
   
   The change is deliberately as small as possible, leaving most
   of the old WMIC handling in place because there is a plan to deprecate
   this class anyway (#3252).
   
   On performance note: executing the check via PowerShell is notably
   slower than with WMIC (low hundreds of millis vs tens of millis).
   However, since this check is used only to detect zombie process
   and only once per tens of seconds, this will hopefully be good enough.
   Much better and faster implementation could be done via ProcessHandle once the minimal
   supported Java moves to 9 or later. There is already a work in progress at #3252 for this, after which only combinations with Java 8 and Windows will use PowerShell for doing the check. Until then this should do.
   
   
   Since windows-2022 was hardcoded precisely because of missing WMIC on newer windows, I propose to change the matrix too. I don't think we need to increase number of tested combinations so just replace windows-2022 with windows-latest.
   
   CI run with windows-2022 available at https://github.com/jbliznak/maven-surefire/actions/runs/21788605653
   CI run with windows-latest https://github.com/jbliznak/maven-surefire/actions/runs/21788596928
   
   
   ---
   
   Following this checklist to help us incorporate your 
   contribution quickly and easily:
   
    - [x] Each commit in the pull request should have a meaningful subject line and body.
    - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [x] Run `mvn clean install` to make sure basic checks pass. A more thorough check will 
          be performed on your pull request automatically.
    - [x] You have run the integration tests successfully (`mvn -Prun-its clean install`).
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under 
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   
    - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2778419159


##########
surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java:
##########
@@ -365,15 +365,15 @@ public void shouldParseBusyboxHoursEtime() {
     }
 
     @Test
-    public void shouldHaveSystemPathToWmicOnWindows() throws Exception {
+    public void shouldHaveSystemPathToPowerShellOnWindows() throws Exception {
         assumeTrue(IS_OS_WINDOWS);
         assumeThat(System.getenv("SystemRoot"), is(notNullValue()));
         assumeThat(System.getenv("SystemRoot"), is(not("")));
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem").isDirectory());
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem\\wmic.exe").isFile());
-        assertThat((Boolean) invokeMethod(PpidChecker.class, "hasWmicStandardSystemPath"))
+        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\WindowsPowerShell\\v1.0").isDirectory());

Review Comment:
   (not a windows user) is this version number something stable? (this looks like something might change in the future with upgrade etc...)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy merged PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "jbliznak (via GitHub)" <gi...@apache.org>.
jbliznak commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2779125400


##########
surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java:
##########
@@ -365,15 +365,15 @@ public void shouldParseBusyboxHoursEtime() {
     }
 
     @Test
-    public void shouldHaveSystemPathToWmicOnWindows() throws Exception {
+    public void shouldHaveSystemPathToPowerShellOnWindows() throws Exception {
         assumeTrue(IS_OS_WINDOWS);
         assumeThat(System.getenv("SystemRoot"), is(notNullValue()));
         assumeThat(System.getenv("SystemRoot"), is(not("")));
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem").isDirectory());
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem\\wmic.exe").isFile());
-        assertThat((Boolean) invokeMethod(PpidChecker.class, "hasWmicStandardSystemPath"))
+        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\WindowsPowerShell\\v1.0").isDirectory());

Review Comment:
   BTW the implementation should work even if powershell is in different location - the same way the WMIC was able to be used from elsewhere if it was found on the PATH. It just prefers this standard location to be used first.
   
   The test itself also doesn't fail if the location is not available but other tests will fail if no powershell is found, again the same as with previous WMIC implementation.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2784525516


##########
.github/workflows/maven-verify.yml:
##########
@@ -49,4 +49,4 @@ jobs:
         !**/hs_err_pid*
         !surefire-its/target/ConsoleOutputIT_*/target/surefire-reports/*-jvmRun*-events.bin
       timeout-minutes: 600
-      os-matrix: '[ "ubuntu-latest", "windows-2022", "macos-latest" ]'
+      os-matrix: '[ "ubuntu-latest", "windows-latest", "macos-latest" ]'

Review Comment:
   And GHA usage is monitored (eventually capped) at org level ("apache") so we do not really want increase too much the usage.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2784525516


##########
.github/workflows/maven-verify.yml:
##########
@@ -49,4 +49,4 @@ jobs:
         !**/hs_err_pid*
         !surefire-its/target/ConsoleOutputIT_*/target/surefire-reports/*-jvmRun*-events.bin
       timeout-minutes: 600
-      os-matrix: '[ "ubuntu-latest", "windows-2022", "macos-latest" ]'
+      os-matrix: '[ "ubuntu-latest", "windows-latest", "macos-latest" ]'

Review Comment:
   And GHA usage is monitored (eventually capped) at org level ("apache:") so we do not really want increase too much the usage.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "jbliznak (via GitHub)" <gi...@apache.org>.
jbliznak commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2779125400


##########
surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java:
##########
@@ -365,15 +365,15 @@ public void shouldParseBusyboxHoursEtime() {
     }
 
     @Test
-    public void shouldHaveSystemPathToWmicOnWindows() throws Exception {
+    public void shouldHaveSystemPathToPowerShellOnWindows() throws Exception {
         assumeTrue(IS_OS_WINDOWS);
         assumeThat(System.getenv("SystemRoot"), is(notNullValue()));
         assumeThat(System.getenv("SystemRoot"), is(not("")));
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem").isDirectory());
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem\\wmic.exe").isFile());
-        assertThat((Boolean) invokeMethod(PpidChecker.class, "hasWmicStandardSystemPath"))
+        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\WindowsPowerShell\\v1.0").isDirectory());

Review Comment:
   BTW the implementation should work even if powershell is in different location - the same way the WMIC was able to be used from elsewhere if it was found on the PATH. It just prefer this standard location to be used first.
   
   The test itself also doesn't fail if the location is not available but other tests will fail if no powershell is found, again the same as with previous WMIC implementation.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2779102831


##########
surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java:
##########
@@ -365,15 +365,15 @@ public void shouldParseBusyboxHoursEtime() {
     }
 
     @Test
-    public void shouldHaveSystemPathToWmicOnWindows() throws Exception {
+    public void shouldHaveSystemPathToPowerShellOnWindows() throws Exception {
         assumeTrue(IS_OS_WINDOWS);
         assumeThat(System.getenv("SystemRoot"), is(notNullValue()));
         assumeThat(System.getenv("SystemRoot"), is(not("")));
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem").isDirectory());
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem\\wmic.exe").isFile());
-        assertThat((Boolean) invokeMethod(PpidChecker.class, "hasWmicStandardSystemPath"))
+        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\WindowsPowerShell\\v1.0").isDirectory());

Review Comment:
   Some old PowerShell versions have been removed recently. We need to take that into account.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2779137519


##########
surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java:
##########
@@ -365,15 +365,15 @@ public void shouldParseBusyboxHoursEtime() {
     }
 
     @Test
-    public void shouldHaveSystemPathToWmicOnWindows() throws Exception {
+    public void shouldHaveSystemPathToPowerShellOnWindows() throws Exception {
         assumeTrue(IS_OS_WINDOWS);
         assumeThat(System.getenv("SystemRoot"), is(notNullValue()));
         assumeThat(System.getenv("SystemRoot"), is(not("")));
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem").isDirectory());
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem\\wmic.exe").isFile());
-        assertThat((Boolean) invokeMethod(PpidChecker.class, "hasWmicStandardSystemPath"))
+        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\WindowsPowerShell\\v1.0").isDirectory());

Review Comment:
   Reasonable, maybe a comment should be added...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "jbliznak (via GitHub)" <gi...@apache.org>.
jbliznak commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2782402435


##########
.github/workflows/maven-verify.yml:
##########
@@ -49,4 +49,4 @@ jobs:
         !**/hs_err_pid*
         !surefire-its/target/ConsoleOutputIT_*/target/surefire-reports/*-jvmRun*-events.bin
       timeout-minutes: 600
-      os-matrix: '[ "ubuntu-latest", "windows-2022", "macos-latest" ]'
+      os-matrix: '[ "ubuntu-latest", "windows-latest", "macos-latest" ]'

Review Comment:
   I guess that is a question for someone maintaining the project. If it is acceptable to have bigger CI matrix, why not. 
   
   BTW this is already being discussed at #3252, we could try to keep this PR as simple as possible.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "jbliznak (via GitHub)" <gi...@apache.org>.
jbliznak commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2779121568


##########
surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java:
##########
@@ -365,15 +365,15 @@ public void shouldParseBusyboxHoursEtime() {
     }
 
     @Test
-    public void shouldHaveSystemPathToWmicOnWindows() throws Exception {
+    public void shouldHaveSystemPathToPowerShellOnWindows() throws Exception {
         assumeTrue(IS_OS_WINDOWS);
         assumeThat(System.getenv("SystemRoot"), is(notNullValue()));
         assumeThat(System.getenv("SystemRoot"), is(not("")));
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem").isDirectory());
-        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\Wbem\\wmic.exe").isFile());
-        assertThat((Boolean) invokeMethod(PpidChecker.class, "hasWmicStandardSystemPath"))
+        assumeTrue(new File(System.getenv("SystemRoot"), "System32\\WindowsPowerShell\\v1.0").isDirectory());

Review Comment:
   not a regular user myself but all googling suggests the location is always the same even if the actual powershell version inside is different, probably to keep compatibility. 
   
   at least one MS reference
   https://learn.microsoft.com/en-us/windows/msix/psf/run-scripts-with-package-support-framework
   
       64-bit computer:
           64-bit executable: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
           32-bit executable: %SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
       32-bit computer:
           32-bit executable: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Use PowerShell instead of WMIC for detecting zombie process on Windows [maven-surefire]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #3258:
URL: https://github.com/apache/maven-surefire/pull/3258#discussion_r2782277778


##########
.github/workflows/maven-verify.yml:
##########
@@ -49,4 +49,4 @@ jobs:
         !**/hs_err_pid*
         !surefire-its/target/ConsoleOutputIT_*/target/surefire-reports/*-jvmRun*-events.bin
       timeout-minutes: 600
-      os-matrix: '[ "ubuntu-latest", "windows-2022", "macos-latest" ]'
+      os-matrix: '[ "ubuntu-latest", "windows-latest", "macos-latest" ]'

Review Comment:
   do we want to keep specific versions of windows and maybe add latest too?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org