Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1750768

Summary: jstack -F forced mode results into "Error occurred during stack walking"
Product: Red Hat Enterprise Linux 7 Reporter: Simeon Andreev <simeon.andreev>
Component: java-1.8.0-openjdkAssignee: Severin Gehwolf <sgehwolf>
Status: CLOSED DUPLICATE QA Contact: OpenJDK QA <java-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 7.4CC: jvanek, loskutov
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-09-17 08:12:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Some output from calling jstack -F and stack on the running Java application process, showing occasional errors when using the -F option. none

Description Simeon Andreev 2019-09-10 12:58:52 UTC
Created attachment 1613578 [details]
Some output from calling jstack -F and stack on the running Java application process, showing occasional errors when using the -F option.

Description of problem:

When using jstack -F, not all thread stacks are listed. Instead, an error is listed for a thread which is in an endless loop due to Java pattern processing.

Version-Release number of selected component (if applicable):

socbl958:/home/sandreev$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

socbl958:/home/sandreev$ cat /etc/redhat-release
Red Hat Enterprise Linux Workstation release 7.4 (Maipo)

How reproducible:


Steps to Reproduce:
1. Run the following snippet, it will result in an endless loop ("expected"):
import java.util.regex.Pattern;

public class TestPattern {
    /** word characters and #@$,.+-[] plus space */
    private static final String PATH_CHARS = "[\\w #@$,.+\\-\\[\\]]";

    /** exact one path character without dot  */
    private static final String PATH_CHARS_NO_DOT = PATH_CHARS.replace(".", "");

    /** ".." or space */
    private static final String BAD_CHARS = "(\\.{2,})|( )";

    /** $(VARIABLE_NAME) */
    private static final String VARIABLE =
                    // 3 variable definition including braces
                    "(\\$\\(" +
                // 4: variable content: word character or _-
                        "([\\w_\\-]+)" +
            "\\))";

    /**
     * each segment must not have neither leading (?! ) nor trailing (?<! ) bad chars (
     * ".." or " ")
     */
    private static final String PATH_SEGMENT =
            "(?!" + BAD_CHARS + ")" +
            "(" +
                    "(" + PATH_CHARS_NO_DOT  + "{1,1})" +
                    "|" +
                    "(" + PATH_CHARS + "){2,}" +
             ")+" +
             "(?<!" + BAD_CHARS + ")";

    private static final String RELATIVE_PATH =
            "(" + PATH_SEGMENT + ")" + "(/" + PATH_SEGMENT + ")*";

    private static final String ABS_PATH = "/" + RELATIVE_PATH;

    /**
     * Two top level groups - absolute path (with variable or not) or relative.
     */
    public static final Pattern PATH_PATTERN = Pattern.compile(
            "(" +
                    // 4 variable
                    "(" + VARIABLE + ")?" +
                    // 5 absolute path
                    "(" + ABS_PATH + ")?" +
            ")" +
            "|" +
            // 18 relative path
            "(" + RELATIVE_PATH + ")"
     );
	
	public static void main(String[] args) {
		System.out.println(PATH_PATTERN.matcher("/workspaces/socbm557/complab/ws-Incorruptus-MX/NoPatch/mixedsignaldevices-master@8472b8bf32f(2)/Incorruptus_MX_Complab").matches());
	}
}
2. Find the process PID of the running Java application (e.g. with jsp).
3. Call jstack -F <PID>.
4. Observe that often, the following error is seen:
Thread 12105: (state = IN_JAVA)
Error occurred during stack walking:
java.lang.NullPointerException
        at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:88)
        at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:45)
        at sun.jvm.hotspot.tools.JStack.run(JStack.java:66)
        at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
        at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
        at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
        at sun.tools.jstack.JStack.main(JStack.java:106)

Actual results:

Often, an error is seen:

Thread 12105: (state = IN_JAVA)
Error occurred during stack walking:
java.lang.NullPointerException
        at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:88)
        at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:45)
        at sun.jvm.hotspot.tools.JStack.run(JStack.java:66)
        at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
        at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
        at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
        at sun.tools.jstack.JStack.main(JStack.java:106)

Expected results:

No error is seen, the stack traces of all threads are listed. E.g. jstack without the forced option does not run into this error.

Additional info:

We use jstack -F in tool which collects a snapshot of running product information, when customers report bugs. Since we collect various information; we would normally use both jstack and jstack -F, but in some customer environments even one jstack  call can take long to finish. So we have opted for using jstack -F.

We recently had a case of an endless loop, reduced to the snippet seen above. It was difficult to find the cause, since the snapshots provided by users were incomplete (see the errors above).

Comment 3 Severin Gehwolf 2019-09-17 08:13:48 UTC
Note that I've marked this as a duplicate of bug 1752173 since we don't need two bugs to track the same issue. I've opted to mark this one as duplicate (but could also have been the other way round).