Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk16u Public archive

Commit

Permalink
8253368: TLS connection always receives close_notify exception
Browse files Browse the repository at this point in the history
Backport-of: a4e082e9857d6acd126fb0734583b4a1e211f9f7
  • Loading branch information
coffeys committed Dec 24, 2020
1 parent be345a2 commit 43f4ae2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
19 changes: 10 additions & 9 deletions src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -820,16 +820,17 @@ private void shutdownInput(
// Is it ready to close inbound?
//
// No need to throw exception if the initial handshake is not started.
if (checkCloseNotify && !conContext.isInputCloseNotified &&
(conContext.isNegotiated || conContext.handshakeContext != null)) {

throw conContext.fatal(Alert.INTERNAL_ERROR,
try {
if (checkCloseNotify && !conContext.isInputCloseNotified &&
(conContext.isNegotiated || conContext.handshakeContext != null)) {
throw new SSLException(
"closing inbound before receiving peer's close_notify");
}

conContext.closeInbound();
if ((autoClose || !isLayered()) && !super.isInputShutdown()) {
super.shutdownInput();
}
} finally {
conContext.closeInbound();
if ((autoClose || !isLayered()) && !super.isInputShutdown()) {
super.shutdownInput();
}
}
}

Expand Down
30 changes: 27 additions & 3 deletions test/jdk/sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,9 +23,10 @@

/*
* @test
* @bug 8184328
* @bug 8184328 8253368
* @summary JDK8u131-b34-socketRead0 hang at SSL read
* @run main/othervm SSLSocketCloseHang
* @run main/othervm SSLSocketCloseHang shutdownInputTest
*/

import java.io.*;
Expand Down Expand Up @@ -72,6 +73,8 @@ public class SSLSocketCloseHang {
*/
static boolean debug = false;

static boolean shutdownInputTest = false;

/*
* If the client or server is doing some kind of object creation
* that the other side depends on, and that thread prematurely
Expand Down Expand Up @@ -145,7 +148,26 @@ void doClientSide() throws Exception {
Thread.sleep(500);
System.err.println("Client closing: " + System.nanoTime());

sslSocket.close();
if (shutdownInputTest) {
try {
sslSocket.shutdownInput();
} catch (SSLException e) {
if (!e.getMessage().contains
("closing inbound before receiving peer's close_notify")) {
throw new RuntimeException("expected different exception message. " +
e.getMessage());
}
}
if (!sslSocket.getSession().isValid()) {
throw new RuntimeException("expected session to remain valid");
}

} else {
sslSocket.close();
}



clientClosed = true;
System.err.println("Client closed: " + System.nanoTime());
}
Expand Down Expand Up @@ -179,6 +201,8 @@ public static void main(String[] args) throws Exception {
if (debug)
System.setProperty("javax.net.debug", "all");

shutdownInputTest = args.length > 0 ? true : false;

/*
* Start the tests.
*/
Expand Down

1 comment on commit 43f4ae2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.