--- old/src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java Mon Sep 11 23:18:33 2017 +++ new/src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java Mon Sep 11 23:18:33 2017 @@ -396,6 +396,9 @@ static final boolean trustNameService = Debug.getBooleanProperty("jdk.tls.trustNameService", false); + static final int retryCloseAttempts = + Debug.getIntegerProperty("jdk.tls.closeRetries", 5); + // // CONSTRUCTORS AND INITIALIZATION CODE // @@ -1794,6 +1797,7 @@ try { int state; + int retryCount = 0; while (((state = getConnectionState()) != cs_CLOSED) && (state != cs_ERROR) && (state != cs_APP_CLOSED)) { @@ -1802,7 +1806,16 @@ try { readRecord(true); } catch (SocketTimeoutException e) { - // if time out, ignore the exception and continue + // if time out, retry as specified by retryCloseAttempts + if (retryCloseAttempts > 0 && retryCount == retryCloseAttempts) { + if ((debug != null) && Debug.isOn("ssl")) { + System.out.println( + Thread.currentThread().getName() + + ", received Exception: " + e); + } + fatal((byte)(-1), "Did not receive close_notify from peer", e); + } + retryCount++; } } } catch (IOException e) {