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

Provide a useful error message when native image fails with OOM #7645

Merged
merged 1 commit into from
Mar 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class NativeImageBuildStep {
*/
private static final String PATH = "PATH";

private static final int OOM_ERROR_VALUE = 137;
private static final String QUARKUS_XMX_PROPERTY = "quarkus.native.native-image-xmx";

@BuildStep(onlyIf = NativeBuild.class)
ArtifactResultBuildItem result(NativeImageBuildItem image) {
return new ArtifactResultBuildItem(image.getPath(), PackageConfig.NATIVE, Collections.emptyMap());
Expand Down Expand Up @@ -328,8 +331,9 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
errorReportLatch));
executor.shutdown();
errorReportLatch.await();
if (process.waitFor() != 0) {
throw new RuntimeException("Image generation failed. Exit code: " + process.exitValue());
int exitCode = process.waitFor();
if (exitCode != 0) {
throw imageGenerationFailed(exitCode, command);
}
Path generatedImage = outputDir.resolve(executableName);
Path finalPath = outputTargetBuildItem.getOutputDirectory().resolve(executableName);
Expand All @@ -343,6 +347,22 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
}
}

private RuntimeException imageGenerationFailed(int exitValue, List<String> command) {
if (exitValue == OOM_ERROR_VALUE) {
if (command.contains("docker") && !IS_LINUX) {
return new RuntimeException("Image generation failed. Exit code was " + exitValue
+ " which indicates an out of memory error. The most likely cause is Docker not being given enough memory. Also consider increasing the Xmx value for native image generation by setting the \""
+ QUARKUS_XMX_PROPERTY + "\" property");
} else {
return new RuntimeException("Image generation failed. Exit code was " + exitValue
+ " which indicates an out of memory error. Consider increasing the Xmx value for native image generation by setting the \""
+ QUARKUS_XMX_PROPERTY + "\" property");
}
} else {
return new RuntimeException("Image generation failed. Exit code: " + exitValue);
}
}

private void checkGraalVMVersion(String version) {
log.info("Running Quarkus native-image plugin on " + version);
final List<String> obsoleteGraalVmVersions = Arrays.asList("1.0.0", "19.0.", "19.1.", "19.2.", "19.3.0");
Expand Down