micronaut-projects / micronaut-gradle-plugin

A Gradle Plugin for Micronaut
Apache License 2.0
66 stars 44 forks source link

SIGSEGV On Alpine/MUSL #442

Open dansiviter opened 2 years ago

dansiviter commented 2 years ago

Expected Behavior

Application runs without crashing.

Actual Behaviour

Application fails with SIGSEGV:

#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000000000003fd6, pid=1, tid=8
#
# JRE version: OpenJDK Runtime Environment Temurin-11.0.14.1+1 (11.0.14.1+1) (build 11.0.14.1+1)
# Java VM: OpenJDK 64-bit Server VM Temurin-11.0.14.1+1 (11.0.14.1+1, mixed mode, tiered, compressed oops, serial gc, linux-amd64)
...

This issue is due to netty/netty#11701: MUSL is not supported.

Raising ticket for awareness of issue for others.

Steps To Reproduce

Create application with Alpine base image.

Environment Information

Example Application

No response

Version

3.4.0

alvarosanchez commented 2 years ago

@dansiviter did you package the application using our build plugins? Was it generated via Micronaut Launch?

Perhaps we can better help users with the micronaut.runtime property, and/or some warning via the build plugins, and/or some feature validation in Launch.

dansiviter commented 2 years ago

It was packaged using Jib gradle plugin using eclipse-temurin:11-jre-alpine image.

alvarosanchez commented 2 years ago

Right, then in that case we can only document it.

petehannam commented 2 years ago

I'm seeing this behaviour as well, when trying to move from Java 11 to Java 17 (and adoptopenjdk/openjdk11 to openjdk:17-alpine as per the Micronaut application plugin). Everything worked fine before, but now it fails with similar to the above:

#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000000000003fd6, pid=1, tid=31
#
# JRE version: OpenJDK Runtime Environment (17.0+14) (build 17-ea+14)
# Java VM: OpenJDK 64-Bit Server VM (17-ea+14, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C 0x0000000000003fd6
#
# Core dump will be written. Default location: core.1 (may not exist)
#
# An error report file with more information is saved as:
# /home/app/hs_err_pid1.log
#
# If you would like to submit a bug report, please visit:
# https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

In trying to diagnose this problem, I've reverted back to using a grade build generated through Micronaut Launch (micronaut version = 3.4.1):

plugins {
    id("com.github.johnrengelman.shadow") version "7.1.2"
    id("io.micronaut.application") version "3.3.2"
    id("com.google.cloud.tools.jib") version "2.8.0"
}

java {
    sourceCompatibility = JavaVersion.toVersion("17")
    targetCompatibility = JavaVersion.toVersion("17")
}

group = "lgbt.switchboard.my"

tasks {
    dockerBuild {
        images = ["${System.env.DOCKER_IMAGE ?: project.name}:$project.version"]
    }

    dockerBuildNative {
        images = ["${System.env.DOCKER_IMAGE ?: project.name}:$project.version"]
    }
    jib {
        to {
            image = "gcr.io/myapp/jib-image"
        }
    }
}
graalvmNative.toolchainDetection = false
micronaut {
    runtime("netty")
    testRuntime("junit5")
    processing {
        incremental(true)
        annotations("lgbt.switchboard.my.*")
    }
}

application {
    mainClass.set("lgbt.switchboard.my.person.service.Application")
}

dependencies {
  annotationProcessor(platform("io.micronaut:micronaut-bom:$micronautVersion"))
  annotationProcessor("io.micronaut:micronaut-inject-java")
  annotationProcessor("io.micronaut:micronaut-http-validation")

  implementation(platform("io.micronaut:micronaut-bom:$micronautVersion"))
  implementation("io.micronaut:micronaut-inject")
  runtimeOnly("io.micronaut:micronaut-runtime")

  ...
}

I didn't configure things to use native transports in netty (apparently the root cause):

micronaut:
  server:
    cors:
      enabled: true

The fix was to not use the default image openjdk:17-alpine and instead use one of the ones listed on the Netty bug page:

tasks.named("dockerfile") {
  baseImage = "azul/zulu-openjdk:17"
}
Image Status
openjdk:17-alpine Doesn't work
eclipse-temurin:17 Works
eclipse-temurin:17-alpine Doesn't work
bellsoft/liberica-openjdk-debian:17 Works
bellsoft/liberica-openjre-alpine:17 Works
azul/zulu-openjdk:17 Works
azul/zulu-openjdk-alpine:17 Doesn't work

Even though the Micronaut docs say the default is false, I tried specifically disabling the Netty native transports - but it didn't help:

micronaut:
  server:
    cors:
      enabled: true
  netty:
    event-loops:
      default:
        prefer-native-transport: false
yawkat commented 2 years ago

You could try the io.netty.transport.noNative=false system property

petehannam commented 2 years ago

@yawkat Doesn't seemingly work:

tasks.named("dockerfile") {
   args("-Dio.netty.transport.noNative=false")
}