micronaut-gradle-plugin icon indicating copy to clipboard operation
micronaut-gradle-plugin copied to clipboard

SIGSEGV On Alpine/MUSL

Open dansiviter opened this issue 3 years ago • 6 comments

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

  • Alpine base image (any version)

Example Application

No response

Version

3.4.0

dansiviter avatar Mar 30 '22 11:03 dansiviter

@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.

alvarosanchez avatar Mar 30 '22 14:03 alvarosanchez

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

dansiviter avatar Mar 30 '22 14:03 dansiviter

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

alvarosanchez avatar Mar 30 '22 14:03 alvarosanchez

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

petehannam avatar Apr 05 '22 12:04 petehannam

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

yawkat avatar Apr 05 '22 12:04 yawkat

@yawkat Doesn't seemingly work:

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

petehannam avatar Apr 05 '22 13:04 petehannam