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

Reviewed-by: xuelei
Backport-of: 6f171b9f0d
This commit is contained in:
Alexey Bakhtin 2021-07-12 10:24:39 +00:00 committed by Vladimir Kempik
parent 3d82b0e634
commit e1d3e73d4e
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()) {