Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Segmentation fault when running angularj in docker container #29

Closed
FusionHS opened this issue Dec 21, 2018 · 3 comments
Closed

Segmentation fault when running angularj in docker container #29

FusionHS opened this issue Dec 21, 2018 · 3 comments

Comments

@FusionHS
Copy link

Hi

I'm trying to run my working spring-boot app in a docker container, but every time I run it, i get something similar to the below logs

OpenJDK 64-Bit Server VM warning: You have loaded library /root/libj2v8_linux_x86_64.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00000000003cf916, pid=6, tid=0x00007fedbd77aae8
#
# JRE version: OpenJDK Runtime Environment (8.0_181-b13) (build 1.8.0_181-b13)
# Java VM: OpenJDK 64-Bit Server VM (25.181-b13 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 3.9.0
# Distribution: Custom build (Tue Oct 23 11:27:22 UTC 2018)
# Problematic frame:
# C  0x00000000003cf916
#
# Core dump written. Default location: /app/core or core.6
#
# An error report file with more information is saved as:
# /app/hs_err_pid6.log
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
#   http://icedtea.classpath.org/bugzilla
#
Segmentation fault (core dumped)

I've tried various base images, including openJDK 8u181 both alpine or non alpine, also openJDK 11 and tried tarent/openjdk-alpine-j2v8. It works when running the jar directly on my windows machine, but I just cant get it running in a docker container on a linux box.

Is there any know issues/solutions for this?

@swaechter
Copy link
Owner

Hey

I also encountered the same warning on several native host systems. As you mentioned the crash is not relatable to lib musl nor glibc (Alpine or not Alpine) - I guess it happens somewhere in the J2V8 library. As always: Wild guessing without a stacktrace ;)

I am not satisfied with the whole J2V8 solution so I wrote a TCP based solution in the last days. TCP and gRPC are now Angular official ways to interact with Angular Universal, so this is the way to go/the future proof way.

I pushed a first runnable version that needs some further love (Better documentation, support for lazy modules and better Node.js error handling).

Is it possible for you to give it a try? I would also be interested in a Docker image (Image with Java 8+ and Node.js).

You can find more information in the README.md and this image: https://raw.githubusercontent.com/swaechter/angularj-universal/master/doc/AngularJ_Universal_HighLevelOverview.png

@FusionHS
Copy link
Author

Sorry for the delay, new year and such.

So I solved the issue by building an imagine with the right binaries for j2v8 built for the alpine image.
Then excluding the packaged one

        <dependency>
            <groupId>ch.swaechter</groupId>
            <artifactId>angularj-universal-renderer-v8</artifactId>
            <version>0.0.3</version>
            <exclusions>
                <exclusion>
                    <groupId>com.eclipsesource.j2v8</groupId>
                    <artifactId>j2v8_linux_x86_64</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

I'll be happy to try the TCP version, but your 0.0.4-SNAPSHOT does not seem to be available on maven, unless I missed some definition for a snapshot repo in the examples.

For reference, here is the dockerfile for the alpine image I'm using. I don't know if this is the right or best way of doing it, but I got sick of things so just left it when it started working.

FROM openjdk:8u181-jdk-alpine

RUN apk add --update --virtual build-dependencies wget git g++ python linux-headers alpine-sdk binutils-gold --no-cache && \

    # Download and build J2V8 4.8.0
    # Source: https://github.com/eclipsesource/J2V8/issues/151
    mkdir /data/ && cd /data/ && git clone https://github.com/eclipsesource/J2V8.git && cd /data/J2V8/ && git checkout 0828fcd5ac2a0f4281e7a5ef913da8cd5a993ac9 && \

    # Set compiler flags
    export CCFLAGS="${CCFLAGS} -fPIC" CXXFLAGS="${CXXFLAGS} -fPIC" CPPFLAGS="${CPPFLAGS} -fPIC" && \

    # Download and build the J2V8 specific node version
    cd /data/J2V8/ && sh ./build-node.sh && \

    cd /data/J2V8/jni && \
    g++ -I ../node -I ../node/deps/v8 -I ../node/deps/v8/include \
        -I ../node/src -I $JAVA_HOME -I $JAVA_HOME/linux  \
        com_eclipsesource_v8_V8Impl.cpp -std=c++11 -fPIC -shared -o /usr/lib/libj2v8_linux_x86_64.so \
        -Wl,--whole-archive ../node/out/Release/obj.target/libnode.a -Wl,--no-whole-archive \
        -Wl,--start-group \
                          ../node/out/Release/obj.target/deps/v8/src/libv8_libbase.a \
                          ../node/out/Release/obj.target/deps/v8/src/libv8_libplatform.a \
                          ../node/out/Release/obj.target/deps/v8/src/libv8_base.a \
                          ../node/out/Release/obj.target/deps/v8/src/libv8_nosnapshot.a \
                          ../node/out/Release/obj.target/deps/v8/src/libv8_libsampler.a \
                          ../node/out/Release/obj.target/deps/uv/libuv.a \
                          ../node/out/Release/obj.target/deps/openssl/libopenssl.a \
                          ../node/out/Release/obj.target/deps/http_parser/libhttp_parser.a \
                          ../node/out/Release/obj.target/deps/gtest/libgtest.a \
                          ../node/out/Release/obj.target/deps/zlib/libzlib.a \
                          ../node/out/Release/obj.target/deps/cares/libcares.a \
        -Wl,--end-group \
        -lrt -z noexecstack -D NODE_COMPATIBLE=1 && \

    # https://github.com/eclipsesource/J2V8/commit/67bfd09f24fece7a0eddcbb0388a572c895c4b8e
    strip --strip-unneeded -R .note -R .comment /usr/lib/libj2v8_linux_x86_64.so && \

    # Cleanup
    apk del build-dependencies && \
    rm -rf /var/cache/apk/* && \
    rm -rf /data/

@swaechter
Copy link
Owner

swaechter commented Jan 26, 2019

Ah, glad to hear that. Where you able to figure out the exact reason like for example some JVM binary related issue or so?

As you mentioned you have to add the OSS Sonatype snapshot repository. Here is a full Maven example:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ch.swaechter</groupId>
    <artifactId>acme</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>ch.swaechter</groupId>
            <artifactId>angularj-universal-renderer-tcp</artifactId>
            <version>0.0.4-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>snapshots-repo</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

Keep in mind that your Docker image also needs a Node.js binary to start the Node.js mini app with the TCP server socket. You can find a working Linux-ish Java configuraiton example in the README.md

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants