8268965: TCP Connection Reset when connecting simple socket to SSL server

Reviewed-by: xuelei
This commit is contained in:
Alexey Bakhtin 2021-07-08 16:44:55 +00:00 committed by Vladimir Kempik
parent 4f322a9b6c
commit 6f171b9f0d
2 changed files with 120 additions and 0 deletions

View file

@ -1777,6 +1777,18 @@ public final class SSLSocketImpl
}
if (autoClose || !isLayered()) {
// Try to clear the kernel buffer to avoid TCP connection resets.
if (conContext.inputRecord instanceof
SSLSocketInputRecord inputRecord && isConnected) {
if (appInput.readLock.tryLock()) {
try {
inputRecord.deplete(false);
} finally {
appInput.readLock.unlock();
}
}
}
super.close();
} else if (selfInitiated) {
if (!conContext.isInboundClosed() && !isInputShutdown()) {