diff options
author | Brian Carlstrom <bdc@google.com> | 2011-01-30 17:30:00 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-01-30 17:30:00 -0800 |
commit | b2d079d59f40de0f5570e1c8156a4777aa784828 (patch) | |
tree | 0cac343324114b691dd6650a69dc53e0c059ed74 /luni/src | |
parent | a03e95456745d6e1e82bc315ec94e850dedcdc59 (diff) | |
parent | aa2be6b82cdf3bb292076d2a614a5f5b40e63123 (diff) | |
download | libcore-b2d079d59f40de0f5570e1c8156a4777aa784828.zip libcore-b2d079d59f40de0f5570e1c8156a4777aa784828.tar.gz libcore-b2d079d59f40de0f5570e1c8156a4777aa784828.tar.bz2 |
am aa2be6b8: SSLSocket.close() should not throw an IOException if there is a problem sending a close notify
* commit 'aa2be6b82cdf3bb292076d2a614a5f5b40e63123':
SSLSocket.close() should not throw an IOException if there is a problem sending a close notify
Diffstat (limited to 'luni/src')
-rw-r--r-- | luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java | 15 | ||||
-rw-r--r-- | luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java | 44 |
2 files changed, 49 insertions, 10 deletions
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java index 4bd91ad..36e7d09 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java @@ -1225,20 +1225,19 @@ public class OpenSSLSocketImpl synchronized (writeLock) { synchronized (readLock) { - IOException pendingException = null; - // Shut down the SSL connection, per se. try { if (handshakeStarted) { BlockGuard.getThreadPolicy().onNetwork(); NativeCrypto.SSL_shutdown(sslNativePointer, fd, this); } - } catch (IOException ex) { + } catch (IOException ignored) { /* - * Note the exception at this point, but try to continue - * to clean the rest of this all up before rethrowing. + * Note that although close() can throw + * IOException, the RI does not throw if there + * is problem sending a "close notify" which + * can happen if the underlying socket is closed. */ - pendingException = ex; } /* @@ -1255,10 +1254,6 @@ public class OpenSSLSocketImpl if (!super.isClosed()) super.close(); } - - if (pendingException != null) { - throw pendingException; - } } } } diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java index 92b152b..621f299 100644 --- a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java +++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java @@ -801,6 +801,50 @@ public class SSLSocketTest extends TestCase { } } + /** + * b/3350645 Test to confirm that an SSLSocket.close() performing + * an SSL_shutdown does not throw an IOException if the peer + * socket has been closed. + */ + public void test_SSLSocket_shutdownCloseOnClosedPeer() throws Exception { + TestSSLContext c = TestSSLContext.create(); + final Socket underlying = new Socket(c.host, c.port); + final SSLSocket wrapping = (SSLSocket) + c.clientContext.getSocketFactory().createSocket(underlying, + c.host.getHostName(), + c.port, + false); + Thread clientThread = new Thread(new Runnable () { + public void run() { + try { + try { + wrapping.startHandshake(); + wrapping.getOutputStream().write(42); + // close the underlying socket, + // so that no SSL shutdown is sent + underlying.close(); + wrapping.close(); + } catch (SSLException expected) { + } + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + clientThread.start(); + + SSLSocket server = (SSLSocket) c.serverSocket.accept(); + server.startHandshake(); + server.getInputStream().read(); + // wait for thread to finish so we know client is closed. + clientThread.join(); + // close should cause an SSL_shutdown which will fail + // because the peer has closed, but it shouldn't throw. + server.close(); + } + public void test_SSLSocket_setSoTimeout_basic() throws Exception { ServerSocket listening = new ServerSocket(0); |