8274524: SSLSocket.close() hangs if it is called during the ssl handshake

Reviewed-by: xuelei
This commit is contained in:
Alexey Bakhtin 2022-02-12 11:54:22 +00:00
parent aa918a6ec4
commit 58dae60da0
2 changed files with 151 additions and 0 deletions

View file

@ -107,6 +107,11 @@ public final class SSLSocketImpl
private static final boolean trustNameService =
Utilities.getBooleanProperty("jdk.tls.trustNameService", false);
/*
* Default timeout to skip bytes from the open socket
*/
private static final int DEFAULT_SKIP_TIMEOUT = 1;
/**
* Package-private constructor used to instantiate an unconnected
* socket.
@ -1781,9 +1786,21 @@ public final class SSLSocketImpl
if (conContext.inputRecord instanceof
SSLSocketInputRecord inputRecord && isConnected) {
if (appInput.readLock.tryLock()) {
int soTimeout = getSoTimeout();
try {
// deplete could hang on the skip operation
// in case of infinite socket read timeout.
// Change read timeout to avoid deadlock.
// This workaround could be replaced later
// with the right synchronization
if (soTimeout == 0)
setSoTimeout(DEFAULT_SKIP_TIMEOUT);
inputRecord.deplete(false);
} catch (java.net.SocketTimeoutException stEx) {
// skip timeout exception during deplete
} finally {
if (soTimeout == 0)
setSoTimeout(soTimeout);
appInput.readLock.unlock();
}
}