hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [18/22] httpcomponents-core git commit: HTTPCORE-207: SocketHttp*Connection classes can leak sockets if the connection is half-closed Contributed by David Koski <david_koski at mac.com>
Date Tue, 09 May 2017 20:04:06 GMT
HTTPCORE-207: SocketHttp*Connection classes can leak sockets if the connection is half-closed
Contributed by David Koski <david_koski at mac.com>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.0.x@818592
13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/e9e665d3
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/e9e665d3
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/e9e665d3

Branch: refs/heads/4.0.x
Commit: e9e665d3bf1a734b8235d2165e075df726736cf1
Parents: 0eb2f62
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Thu Sep 24 19:06:31 2009 +0000
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Thu Sep 24 19:06:31 2009 +0000

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               |  3 +++
 .../http/impl/SocketHttpClientConnection.java   | 24 +++++++++++--------
 .../http/impl/SocketHttpServerConnection.java   | 25 ++++++++++++--------
 3 files changed, 32 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e9e665d3/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 61b0823..3a3b116 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,5 +1,8 @@
 Changes since 4.0.1
 
+* [HTTPCORE-207] SocketHttp*Connection classes can leak sockets if the connection is half-closed
+  Contributed by David Koski <david_koski at mac.com>
+
 * [HTTPCORE-201] OSGi Export-Package to specify release version
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e9e665d3/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java b/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
index f2ddb06..3b968cf 100644
--- a/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
+++ b/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
@@ -245,20 +245,24 @@ public class SocketHttpClientConnection
             return;
         }
         this.open = false;
-        doFlush();
+        Socket sock = this.socket;
         try {
+            doFlush();
             try {
-                this.socket.shutdownOutput();
-            } catch (IOException ignore) {
+                try {
+                    sock.shutdownOutput();
+                } catch (IOException ignore) {
+                }
+                try {
+                    sock.shutdownInput();
+                } catch (IOException ignore) {
+                }
+            } catch (UnsupportedOperationException ignore) {
+                // if one isn't supported, the other one isn't either
             }
-            try {
-                this.socket.shutdownInput();
-            } catch (IOException ignore) {
-            }
-        } catch (UnsupportedOperationException ignore) {
-            // if one isn't supported, the other one isn't either
+        } finally {
+            sock.close();
         }
-        this.socket.close();
     }
     
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e9e665d3/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java b/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
index 437bd00..5d006c8 100644
--- a/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
+++ b/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
@@ -262,20 +262,25 @@ public class SocketHttpServerConnection extends
             return;
         }
         this.open = false;
-        doFlush();
+        this.open = false;
+        Socket sock = this.socket;
         try {
+            doFlush();
             try {
-                this.socket.shutdownOutput();
-            } catch (IOException ignore) {
-            }
-            try {
-                this.socket.shutdownInput();
-            } catch (IOException ignore) {
+                try {
+                    sock.shutdownOutput();
+                } catch (IOException ignore) {
+                }
+                try {
+                    sock.shutdownInput();
+                } catch (IOException ignore) {
+                }
+            } catch (UnsupportedOperationException ignore) {
+                // if one isn't supported, the other one isn't either
             }
-        } catch (UnsupportedOperationException ignore) {
-            // if one isn't supported, the other one isn't either
+        } finally {
+            sock.close();
         }
-        this.socket.close();
     }
     
 }


Mime
View raw message