JDK-8264944 : JSSE Session Reuse is Flaky
  • Type: Bug
  • Component: security-libs
  • Sub-Component: javax.net.ssl
  • Affected Version: 11.0.10
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2021-04-04
  • Updated: 2021-04-26
  • Resolved: 2021-04-26
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
The PR https://github.com/square/okhttp/pull/6616 shows a test using OkHttp client to connect to a local mock server. It fails around 50% of the time.

The sun.security.util.MemoryCache inside sun.security.ssl.SSLSessionContextImpl appears to be unreliable as to when it will clear out entries.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Checkout https://github.com/square/okhttp and switch to PR https://github.com/square/okhttp/pull/6616

Run the test SessionReuseTest

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test should confirm that two sequential requests with fresh connections reuse the same SSL session.  
ACTUAL -
Test fails because a second session is created. Debugging is difficult because the logic in sun.security.ssl.SSLSessionContextImpl is JDK internal, but by the time the second client lookup via "localhost:50701" type key is made the cache is empty again.

FREQUENCY : often



Comments
This issue could be addressed in the update for JDK-8245576, where the session index will be modified to support more generic cases.
26-04-2021

Got the following results on Windows 10: > Task :mockwebserver:jar file or directory 'C:\Users\tongwan\Documents\JI-9069769\okhttp\mockwebserver\build\classes\java\main', not found Caching disabled for task ':mockwebserver:jar' because: Build cache is disabled Task ':mockwebserver:jar' is not up-to-date because: No history is available. file or directory 'C:\Users\tongwan\Documents\JI-9069769\okhttp\mockwebserver\build\classes\java\main', not found file or directory 'C:\Users\tongwan\Documents\JI-9069769\okhttp\mockwebserver\build\resources\main', not found :mockwebserver:jar (Thread[Execution worker for ':',5,main]) completed. Took 0.297 secs. :mockwebserver:compileTestJava (Thread[Execution worker for ':' Thread 6,5,main]) started. > Task :mockwebserver:compileTestJava FAILED :mockwebserver:compileTestJava (Thread[Execution worker for ':' Thread 6,5,main]) completed. Took 0.005 secs. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':mockwebserver:compileTestJava'. > Failed to calculate the value of task ':mockwebserver:compileTestJava' property 'javaCompiler'. > Could not list the subkeys of registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK': could open registry key (errno 5)
09-04-2021

Additional information from the submitter: If you have Intellij and git installed already, these steps should take about 5 minutes I hope. Clone the repo and switch to the PR (example steps from https://stackoverflow.com/a/30584951/1542667) git clone https://github.com/square/okhttp git fetch origin pull/6616/head:pr6616 git checkout pr6616 Open the directory in Intellij (or other IDE) Run test SessionReuseTest. May take 2 or 3 runs as the behaviour of MemoryCache seems non predictable. To run test in command line: ./gradlew clean test --tests SessionReuseTest -i
09-04-2021

Requested more details of running the reproducer from the submitter.
06-04-2021