diff options
author | mckev <mckev@amazon.com> | 2014-12-09 18:42:24 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-10 02:42:55 +0000 |
commit | 7bccf71e649bc440920ee814c8f09c438ab9fa10 (patch) | |
tree | 8fd06f1c330fa30168b5b94ce79fdbe9c00076db /net/test/android | |
parent | b4fcf221cd9f52f7c21378200c64d4179da747c4 (diff) | |
download | chromium_src-7bccf71e649bc440920ee814c8f09c438ab9fa10.zip chromium_src-7bccf71e649bc440920ee814c8f09c438ab9fa10.tar.gz chromium_src-7bccf71e649bc440920ee814c8f09c438ab9fa10.tar.bz2 |
Always close SSL socket in TestWebServer
This fixes a bug where TestWebServer leaves a socket open, which can
lead to a deadlock in some circumstances.
BUG=424418
Review URL: https://codereview.chromium.org/663683002
Cr-Commit-Position: refs/heads/master@{#307625}
Diffstat (limited to 'net/test/android')
-rw-r--r-- | net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java b/net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java index 6121a2a..dd40220 100644 --- a/net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java +++ b/net/test/android/javatests/src/org/chromium/net/test/util/TestWebServer.java @@ -612,8 +612,9 @@ public class TestWebServer { HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0); while (!mIsCancelled) { + Socket socket = null; try { - Socket socket = mSocket.accept(); + socket = mSocket.accept(); DefaultHttpServerConnection conn = new DefaultHttpServerConnection(); conn.bind(socket, params); @@ -628,8 +629,9 @@ public class TestWebServer { HttpResponse response = mServer.getResponse(request); conn.sendResponseHeader(response); conn.sendResponseEntity(response); - conn.close(); + conn.close(); + socket = null; } catch (IOException e) { // normal during shutdown, ignore Log.w(TAG, e); @@ -641,6 +643,18 @@ public class TestWebServer { // DefaultHttpServerConnection's close() throws an // UnsupportedOperationException. Log.w(TAG, e); + } finally { + // Since DefaultHttpServerConnection can raise an exception + // during conn.close() (in the case of SSL), we always force + // the socket to close, since it may be left open. This will + // be a no-op if the connection managed to close the socket. + if (socket != null) { + try { + socket.close(); + } catch (IOException ignored) { + // safe to ignore + } + } } } try { |