https://bz.apache.org/bugzilla/show_bug.cgi?id=58566

            Bug ID: 58566
           Summary: NoSuchMethodError and JVM crash when running HTTPS
                    test with Tomcat 7 (o.a.t.util.net.TestSsl)
           Product: Tomcat Native
           Version: 1.2.0
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Library
          Assignee: dev@tomcat.apache.org
          Reporter: knst.koli...@gmail.com

Tomcat Native 1.2.0 is unusable for HTTPS with Tomcat 7, 8 due to missing APIs
on java side.

Apparently it can be used for plain HTTP and AJP, as other Tomcat 7 tests
(using plain HTTP) pass successfully.

To reproduce:
===============
1) Run org.apache.tomcat.util.net.TestSsl test standalone with Tomcat 7, by
placing the following line into build.properties

test.entry=org.apache.tomcat.util.net.TestSsl

I was testing Tomcat 7 trunk (at r1711498)

2) I was running Ant with JAVA_HOME=JDK 8u66 (32-bit) on Windows 7.

Notes:
=========
1) Ant build with this single test was running for 17 minutes. Two tests were
run

- [testSimpleSsl] printed NoSuchMethodError and hung for 17 minutes
- [testKeyPass] crashed the JVM.

2) The "TEST-org.apache.tomcat.util.net.TestSsl.APR.txt" after JVM crash is
effectively empty.

You need to catch console output of Ant by redirecting it into a file. The
console output has NoSuchMethodError and other messages.

Errors:
========
1)
    [junit] SEVERE: Failed to initialize connector [Connector[HTTP/1.1-auto-1]]
    [junit] org.apache.catalina.LifecycleException: Failed to initialize
component [Connector[HTTP/1.1-auto-1]]
    [junit]     at
org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
    [junit]     at
org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
    [junit]     at
org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    [junit]     at
org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:821)
    [junit]     at
org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    [junit]     at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
    [junit]     at org.apache.catalina.startup.Tomcat.start(Tomcat.java:339)
    [junit]     at
org.apache.catalina.startup.TomcatBaseTest$TomcatWithFastSessionIDs.start(TomcatBaseTest.java:793)
    [junit]     at
org.apache.tomcat.util.net.TestSsl.testSimpleSsl(TestSsl.java:61)
...
    [junit] Caused by: java.lang.NoSuchMethodError: sniCallBack
    [junit]     at org.apache.tomcat.jni.SSLContext.make(Native Method)
    [junit]     at
org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:573)
    [junit]     at
org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:651)
    [junit]     at
org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:434)
    [junit]     at
org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
    [junit]     at
org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    [junit]     ... 33 more

2) From JVM crash file:

[[[
Stack: [0x17440000,0x17490000],  sp=0x1748f504,  free space=317k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0xe26df]
C  [tcnative-1.dll+0x9d73]
C  [tcnative-1.dll+0xc905d]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.apache.tomcat.jni.SSLSocket.handshake(J)I+0
j  org.apache.tomcat.util.net.AprEndpoint.setSocketOptions(J)Z+106
j  org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run()V+34
j 
java.util.concurrent.ThreadPoolExecutor.runWorker(Ljava/util/concurrent/ThreadPoolExecutor$Worker;)V+95
j  java.util.concurrent.ThreadPoolExecutor$Worker.run()V+5
j  org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run()V+4
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub
]]]


Source code
============
>From quick look into native implementation of SSLContext.make() (sslcontext.c),

[[[
    /* Cache Java side SNI callback if not already cached */
    if (ssl_context_class == NULL) {
        ssl_context_class = (*e)->NewGlobalRef(e, o);
        sni_java_callback = (*e)->GetStaticMethodID(e, ssl_context_class,
                                                    "sniCallBack",
"(JLjava/lang/String;)J");
    }
]]]

1) There is no test for success of GetStaticMethodID() call.
2) There is a race condition. Testing that ssl_context_class is not NULL does
not mean that sni_java_callback has already been initialized.

As stacktrace above shows, SSLContext.make() is called from AprEndpoint.bind(),
so a race here is unlikely unless someone initializes several connectors
concurrently at the same time. It explains the JVM crash in the tests, as the
first call results in NoSuchMethodError, but the second call succeeds with
ssl_context_class check and crashes later.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to