Skip to content

Commit ec89f1b

Browse files
committed
8274736: Concurrent read/close of SSLSockets causes SSLSessions to be invalidated unnecessarily
Reviewed-by: mdoerr Backport-of: 8822d41fdcc2c2d568badd72635dc587d21dbd63
1 parent b07b90f commit ec89f1b

File tree

3 files changed

+435
-6
lines changed

3 files changed

+435
-6
lines changed

src/java.base/share/classes/sun/security/ssl/TransportContext.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package sun.security.ssl;
2727

2828
import java.io.IOException;
29+
import java.net.SocketException;
2930
import java.security.AccessControlContext;
3031
import java.security.AccessController;
3132
import java.security.PrivilegedAction;
@@ -365,7 +366,12 @@ SSLException fatal(Alert alert, String diagnostic,
365366

366367
// invalidate the session
367368
if (conSession != null) {
368-
conSession.invalidate();
369+
// In the case of a low-layer transport error, we want to prevent
370+
// the session from being invalidated since this is not a TLS-level
371+
// error event.
372+
if (!(cause instanceof SocketException)) {
373+
conSession.invalidate();
374+
}
369375
}
370376

371377
if (handshakeContext != null &&

test/jdk/javax/net/ssl/templates/SSLSocketTemplate.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -209,22 +209,22 @@ protected void configureServerSocket(SSLServerSocket socket) {
209209
/*
210210
* Is the server ready to serve?
211211
*/
212-
private final CountDownLatch serverCondition = new CountDownLatch(1);
212+
protected final CountDownLatch serverCondition = new CountDownLatch(1);
213213

214214
/*
215215
* Is the client ready to handshake?
216216
*/
217-
private final CountDownLatch clientCondition = new CountDownLatch(1);
217+
protected final CountDownLatch clientCondition = new CountDownLatch(1);
218218

219219
/*
220220
* What's the server port? Use any free port by default
221221
*/
222-
private volatile int serverPort = 0;
222+
protected volatile int serverPort = 0;
223223

224224
/*
225225
* Define the server side of the test.
226226
*/
227-
private void doServerSide() throws Exception {
227+
protected void doServerSide() throws Exception {
228228
// kick start the server side service
229229
SSLContext context = createServerSSLContext();
230230
SSLServerSocketFactory sslssf = context.getServerSocketFactory();
@@ -470,7 +470,15 @@ public static SSLContext createSSLContext(
470470
* Both sides can throw exceptions, but do you have a preference
471471
* as to which side should be the main thread.
472472
*/
473-
private static final boolean separateServerThread = false;
473+
private final boolean separateServerThread;
474+
475+
public SSLSocketTemplate() {
476+
this(false);
477+
}
478+
479+
public SSLSocketTemplate(boolean sepSrvThread) {
480+
this.separateServerThread = sepSrvThread;
481+
}
474482

475483
/*
476484
* Boot up the testing, used to drive remainder of the test.

0 commit comments

Comments
 (0)