Skip to content

Commit

Permalink
Win native file access race: print processes and file handles
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed Nov 2, 2023
1 parent a8db319 commit 653731b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/daily.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ jobs:
- name: Install helmfile through windows scoop
shell: bash
run: scoop install helmfile
- name: Download Sysinternals Handle program used for native race debugging
shell: pwsh
run: Invoke-WebRequest https://download.sysinternals.com/files/Handle.zip -OutFile .\handle.zip
- name: Unzip Sysinternals Handle
shell: pwsh
run: Expand-Archive .\handle.zip -DestinationPath .
- name: Download Maven Repo
uses: actions/download-artifact@v3
with:
Expand All @@ -353,7 +359,7 @@ jobs:
- name: Build in Native mode
shell: bash
run: |
mvn -B -fae -s .github/mvn-settings.xml clean install -Pframework,examples,native -Dquarkus.native.container-build=false -Dquarkus.platform.version="${{ matrix.quarkus-version }}"
mvn -B -fae -s .github/mvn-settings.xml clean install -Pframework,examples,native -Dquarkus.native.container-build=false -Dquarkus.platform.version="${{ matrix.quarkus-version }}" -Denable-win-race-debug=true
- name: Zip Artifacts
shell: bash
if: failure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import static io.quarkus.test.utils.FileUtils.findTargetFile;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Optional;
import java.util.ServiceLoader;

import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ExplodedExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
Expand All @@ -24,11 +26,13 @@
import io.quarkus.test.common.PathTestHelper;
import io.quarkus.test.services.QuarkusApplication;
import io.quarkus.test.services.quarkus.model.QuarkusProperties;
import io.quarkus.test.utils.Command;

public class ProdQuarkusApplicationManagedResourceBuilder extends ArtifactQuarkusApplicationManagedResourceBuilder {

protected static final String TARGET = "target";

private static final Logger LOG = Logger.getLogger(ProdQuarkusApplicationManagedResourceBuilder.class.getName());
private static final String NATIVE_RUNNER = "-runner";
private static final String EXE = ".exe";
private static final String JVM_RUNNER = "-runner.jar";
Expand Down Expand Up @@ -79,12 +83,34 @@ public void build() {
managedResource.onPreBuild();
copyResourcesToAppFolder();
if (managedResource.needsBuildArtifact()) {
this.artifact = tryToReuseOrBuildArtifact();
try {
this.artifact = tryToReuseOrBuildArtifact();
} catch (Throwable t) {
debugFileAccessRaceOnWindows();
throw t;
}
}

managedResource.onPostBuild();
}

private void debugFileAccessRaceOnWindows() {
if (OS.current() == OS.WINDOWS && Boolean.getBoolean("enable-win-race-debug")) {
LOG.info("List all running processes:");
ProcessHandle.allProcesses().forEach(processHandle -> {
LOG.infof("pid - '%s', is alive - '%b', command - '%s', arguments - '%s'", processHandle.pid(),
processHandle.isAlive(), processHandle.info().command().orElse(""),
processHandle.info().arguments());
});
LOG.info("Print all file open handles:");
try {
new Command(".\\handle.exe -accepteula").onDirectory(Path.of(System.getenv("GITHUB_WORKSPACE"))).runAndWait();
} catch (IOException | InterruptedException e) {
throw new RuntimeException("Failed to run 'handle.exe': " + e.getMessage());
}
}
}

protected QuarkusManagedResource findManagedResource() {
for (QuarkusApplicationManagedResourceBinding binding : managedResourceBindingsRegistry) {
if (binding.appliesFor(getContext())) {
Expand Down

0 comments on commit 653731b

Please sign in to comment.