[ 
https://issues.apache.org/jira/browse/SUREFIRE-1573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17140640#comment-17140640
 ] 

Scott Cameron commented on SUREFIRE-1573:
-----------------------------------------

I'm encountering this as well.  This was driving me crazy debugging it... our 
tests passed with 2.20 but some of the tests failed some of the time with 
2.20.1.  And different tests each time.

It turned out that it was failing when one of our components was trying to 
remove a temporary cache file.  The file deletion failed because of a 
{{SHARING_VIOLATION}} and I saw that the cmd.exe running this wmic command, 
inexplicably, had a handle to the file also.  I guess whether or not my test 
failed depended on the timing of when the cmd.exe runs relative to the time my 
cache file was created.

This is pretty bad for us, because it means that we have to disable this cache 
if we want to work with any version of Surefire greater than 2.20.  And since 
we recently updated to JUnit 5, we need quite a recent version of Surefire.

Unfortunately, it doesn't look like there's a way to control this in Java:

[https://github.com/openjdk/jdk/blob/6bab0f539fba8fb441697846347597b4a0ade428/src/java.base/windows/native/libjava/ProcessImpl_md.c#L331]

The {{bInheritHandles}} argument is hardcode to {{TRUE}}.

Maybe instead of running wmic you could call the WMI API directly?  It is a COM 
API, so you'd probably need to use a Java-COM bridge.  Here's a post that list 
a few options, specifically in the context of WMI:

[https://stackoverflow.com/a/4638004/1040479]

(Watch out for the jWMI utility... there's a comment saying it also just 
launches a cmd.exe under the hood)

Anything you can do to fix this would sure be appreciated on our side.  We're a 
little stuck here!

> PpidChecker inherits and blocks resources from tests while checking if the 
> forked VM is still alive
> ---------------------------------------------------------------------------------------------------
>
>                 Key: SUREFIRE-1573
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1573
>             Project: Maven Surefire
>          Issue Type: Bug
>    Affects Versions: 2.22.0
>         Environment: Windows, our tests create temporary files using 
> native-code (std::fstream) and remove or rename them using boost::filesystem. 
> Java 1.8.
>            Reporter: Marcus Ackermann
>            Priority: Critical
>
> On Windows, the PpidChecker executes wmic through cmd by starting a new 
> process. Java calls {{CreateProcess}} with the flag {{bInheritHandles=TRUE}}.
> When I create a temporary file in a test, it happens that this file can 
> neither be removed nor deleted. The error code is the following (from 
> https://docs.microsoft.com/en-us/windows/desktop/debug/system-error-codes--0-499-)
> {code:java}
> ERROR_SHARING_VIOLATION
> 32 (0x20)
> The process cannot access the file because it is being used by another 
> process.{code}
> I found out that this sharing violation is due to the fact that the process 
> started from PpidChecker also owns the file inherited from the test process.
> This seems to be a side-effect of the new monitoring mechanism for the forked 
> VM introduced in 2.20.1 with SUREFIRE-1302.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to