Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Use tini to prevent JVM as pid1 errors #317

Closed
ash211 opened this issue May 30, 2017 · 1 comment
Closed

Use tini to prevent JVM as pid1 errors #317

ash211 opened this issue May 30, 2017 · 1 comment

Comments

@ash211
Copy link

ash211 commented May 30, 2017

https://github.com/krallin/tini

quick summary is running JVMs as pid1 in dockerfiles cause problems -- search for Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to get pid of LinuxThreads manager thread at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:86) to see examples

@ash211
Copy link
Author

ash211 commented May 31, 2017

The full stacktrace of what we were seeing is available here: palantir/conjure-java-runtime#403

Here's some more analysis I did internally on the stacktrace:

Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to get pid of LinuxThreads manager thread
    at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:86)
    ... 64 more

The reason PID1 is important is that there's a bug in the JRE that doesn't correctly handle the JRE being pid1 (and having more child processes than expected).

The above stacktrace has LinuxVirtualMachine.java/#86 in it from the call to native method getLinuxThreadsManager a few lines earlier. LinuxVirtualMachine.c#255

The purpose of that method seems to be to get the main linux thread from which other linux threads of the JVM were spawned from.

It does this by counting how many children the current pid has, by looking through all files that match /proc/[0-9]+ in forEachProcess

Of course because the JVM is pid 1, every other process in the docker image has pid 1 as its parent. So the count of processes with ppid==1 is > 1.

So the if statements at LinuxVirtualMachine.c#273 and LinuxVirtualMachine.c#285 don't hit, and the C function throws the exception, which is then seen in the stacktrace:

Any method that eventually calls sun.tools.attach.LinuxVirtualMachine.<init> triggers this code path and causes an exception, and the ALPN injection calls this as well as some other JVM cli tools like jmap and jstack.

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

1 participant