Mercurial > hg > icedtea8-forest > jdk
changeset 14925:6336cdcdcb3e
8253368: TLS connection always receives close_notify exception
Reviewed-by: xuelei
author | coffeys |
---|---|
date | Wed, 23 Dec 2020 12:26:44 +0000 |
parents | 1c7a96e0ff00 |
children | 7c7b1d67d6e6 |
files | src/share/classes/sun/security/ssl/SSLSocketImpl.java test/sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java |
diffstat | 2 files changed, 37 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/sun/security/ssl/SSLSocketImpl.java Mon Oct 17 13:04:33 2016 +0530 +++ b/src/share/classes/sun/security/ssl/SSLSocketImpl.java Wed Dec 23 12:26:44 2020 +0000 @@ -631,16 +631,17 @@ // 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(); + } } }
--- a/test/sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java Mon Oct 17 13:04:33 2016 +0530 +++ b/test/sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java Wed Dec 23 12:26:44 2020 +0000 @@ -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 @@ -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.*; @@ -72,6 +73,8 @@ */ 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 @@ -145,7 +148,26 @@ 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()); } @@ -179,6 +201,8 @@ if (debug) System.setProperty("javax.net.debug", "all"); + shutdownInputTest = args.length > 0 ? true : false; + /* * Start the tests. */