RFR: 8309305: sun/security/ssl/SSLSocketImpl/BlockedAsyncClose.java fails with jtreg test timeout

Matthew Donovan mdonovan at openjdk.org
Thu Jun 8 14:32:04 UTC 2023


This PR improves the reliability of the BlockedAsyncClose test by addressing an edge case/race condition between the two test threads. The purpose of the test is to verify that an SSLSocket can be closed if a thread is blocked in a write operation. 

The test starts a "write" thread that writes data to a socket until the output buffer was filled, causing the write operation to block. The main thread then calls `SSLSocket.close()`. The original code used `Thread.sleep(1000)` to wait for the write-thread to block. However, 1 second isn't always long enough and if the write-thread isn't blocked and the output buffer is full (or almost full), the `socket.close()` call may block when it tries to send the close_notify alert. This is the condition that caused this bug.

My change uses a Lock to determine if the write thread is blocked. In the write thread, the lock creates a critical section around the `write()` call. The main thread uses `tryLock()` with a timeout to determine that the write() call is taking too long and thus likely blocked. 

While there, I also updated the test to use the SSLContextTemplate class.

-------------

Commit messages:
 - 8309305: sun/security/ssl/SSLSocketImpl/BlockedAsyncClose.java fails with jtreg test timeout

Changes: https://git.openjdk.org/jdk/pull/14378/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14378&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8309305
  Stats: 57 lines in 1 file changed: 20 ins; 24 del; 13 mod
  Patch: https://git.openjdk.org/jdk/pull/14378.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14378/head:pull/14378

PR: https://git.openjdk.org/jdk/pull/14378



More information about the security-dev mailing list