You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2009/09/24 21:06:36 UTC

svn commit: r818592 - in /httpcomponents/httpcore/branches/4.0.x: RELEASE_NOTES.txt httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java

Author: olegk
Date: Thu Sep 24 19:06:31 2009
New Revision: 818592

URL: http://svn.apache.org/viewvc?rev=818592&view=rev
Log:
HTTPCORE-207: SocketHttp*Connection classes can leak sockets if the connection is half-closed
Contributed by David Koski <david_koski at mac.com>

Modified:
    httpcomponents/httpcore/branches/4.0.x/RELEASE_NOTES.txt
    httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
    httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java

Modified: httpcomponents/httpcore/branches/4.0.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.0.x/RELEASE_NOTES.txt?rev=818592&r1=818591&r2=818592&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.0.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/branches/4.0.x/RELEASE_NOTES.txt Thu Sep 24 19:06:31 2009
@@ -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>
 

Modified: httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java?rev=818592&r1=818591&r2=818592&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java (original)
+++ httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java Thu Sep 24 19:06:31 2009
@@ -245,20 +245,24 @@
             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();
     }
     
 }

Modified: httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java?rev=818592&r1=818591&r2=818592&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java (original)
+++ httpcomponents/httpcore/branches/4.0.x/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java Thu Sep 24 19:06:31 2009
@@ -262,20 +262,25 @@
             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();
     }
     
 }