从 docker 运行时出现 Java SIGSEGV 错误

问题描述 投票:0回答:3

我没有Java经验,我可以从开发中成功运行我的代码。但只有当我构建项目并从 docker 运行它时,我才收到这样的错误。

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00000000000200a6, pid=1, tid=0x00007ff7227f9b10
#
# JRE version: OpenJDK Runtime Environment (8.0_212-b04) (build 1.8.0_212-b04)
# Java VM: OpenJDK 64-Bit Server VM (25.212-b04 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 3.12.0
# Distribution: Custom build (Sat May  4 17:33:35 UTC 2019)
# Problematic frame:
# C  0x00000000000200a6
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /opt/my_project/hs_err_pid1.log
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
#   https://icedtea.classpath.org/bugzilla
#

我按照错误消息使用

ulimit -c unlimited
,将其添加到 docker 命令中:
docker run --ulimit core=-1 --env-file -t my_project
,但仍然没有帮助,并收到另一个类似的错误

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00000000000200a6, pid=1, tid=0x00007eff79c95b10
#
# JRE version: OpenJDK Runtime Environment (8.0_212-b04) (build 1.8.0_212-b04)
# Java VM: OpenJDK 64-Bit Server VM (25.212-b04 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 3.12.0
# Distribution: Custom build (Sat May  4 17:33:35 UTC 2019)
# Problematic frame:
# C  0x00000000000200a6
#
# Core dump written. Default location: /opt/my_project/core or core.1
#
# An error report file with more information is saved as:
# /opt/my_project/hs_err_pid1.log
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
#   https://icedtea.classpath.org/bugzilla
#

这是我的 Dockerfile

FROM openjdk:8-jre-alpine
ADD ./build/libs/ /opt/my_project
RUN apk update && apk add --no-cache libc6-compat && ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
WORKDIR /opt/my_project
CMD ["java", "-jar", "my_project.jar"]

我不知道该错误是否与java环境或docker或其他什么有关。感谢您的帮助!

编辑:

在这一行运行时出现错误:

Logging logging = LoggingOptions.newBuilder().setCredentials(googleCredentials).setProjectId(projectId).build().getService();
java linux docker segmentation-fault
3个回答
7
投票

这是通过使用基于 debian 的镜像而不是 alpine 来解决的。

感谢评论区的各位!


3
投票

只是在这里记录我们自己的经验,这证实了rahmathd的答案。

我们使用的是基于高山的 Amazon Corretto:

FROM amazoncorretto/amazoncorretto:11-alpine-jre

RUN apk --update --no-cache add tzdata && apk add --no-cache libstdc++ && apk add --no-cache libc6-compat && ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

ENV TZ Asia/Tokyo

以下两条消息之一伴随着每次运行应用程序几秒钟时发生的崩溃。

1)

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fbd3196c5d6, pid=1, tid=60
#
# JRE version: OpenJDK Runtime Environment Corretto-11.0.8.10.1 (11.0.8+10) (build 11.0.8+10-LTS)
# Java VM: OpenJDK 64-Bit Server VM Corretto-11.0.8.10.1 (11.0.8+10-LTS, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C  [ld-musl-x86_64.so.1+0x235d6]  free+0x28
#
# Core dump will be written. Default location: //core
#
# An error report file with more information is saved as:
# //hs_err_pid1.log
[thread 301 also had an error]
[thread 37 also had an error]
#
# 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.
#

2)

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

切换到基于 Ubuntu 和 Amazon Linux 的 Corretto 也为我们解决了这个问题。


0
投票

我使用 Dockerfile 中的以下步骤解决了 eclipse-temurin:17-jre-alpine 图像中的相同 SIGSEGV 错误:

RUN apk --no-cache add gcompat
ENV LD_PRELOAD=/lib/libgcompat.so.0

更多详细信息和来源是这里

© www.soinside.com 2019 - 2024. All rights reserved.