hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1030045 - in /httpcomponents/httpcore/trunk: ./ httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/
Date Tue, 02 Nov 2010 14:02:35 GMT
Author: olegk
Date: Tue Nov  2 14:02:35 2010
New Revision: 1030045

URL: http://svn.apache.org/viewvc?rev=1030045&view=rev
Log:
HTTPCORE-240: DefaultConnectingIOReactor leaks a socket descriptor if the session request
fails

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1030045&r1=1030044&r2=1030045&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Tue Nov  2 14:02:35 2010
@@ -1,4 +1,8 @@
-Changes since 4.1-BETA2
+Release 4.1
+-------------------
+
+* [HTTPCORE-240]: DefaultConnectingIOReactor leaks a socket descriptor if the session request
fails.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
 
 * [HTTPCORE-239]: The ChunkEncoder could request for a negative buffer limit causing an 
   IllegalArgumentException.

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=1030045&r1=1030044&r2=1030045&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
Tue Nov  2 14:02:35 2010
@@ -516,6 +516,13 @@ public abstract class AbstractMultiworke
         } catch (InterruptedException ignore) {
         }
     }
+    
+    static void closeChannel(final Channel channel) {
+        try {
+            channel.close();
+        } catch (IOException ignore) {
+        }
+    }
 
     static class Worker implements Runnable {
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java?rev=1030045&r1=1030044&r2=1030045&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
Tue Nov  2 14:02:35 2010
@@ -222,11 +222,11 @@ public class DefaultConnectingIOReactor 
             SocketChannel socketChannel;
             try {
                 socketChannel = SocketChannel.open();
-                socketChannel.configureBlocking(false);
             } catch (IOException ex) {
                 throw new IOReactorException("Failure opening socket", ex);
             }
             try {
+                socketChannel.configureBlocking(false);
                 validateAddress(request.getLocalAddress());
                 validateAddress(request.getRemoteAddress());
 
@@ -243,18 +243,18 @@ public class DefaultConnectingIOReactor 
                     return;
                 }
             } catch (IOException ex) {
+                closeChannel(socketChannel);
                 request.failed(ex);
                 return;
             }
 
             SessionRequestHandle requestHandle = new SessionRequestHandle(request);
-            SelectionKey key;
             try {
-                key = socketChannel.register(this.selector, SelectionKey.OP_CONNECT, requestHandle);
+                SelectionKey key = socketChannel.register(this.selector, SelectionKey.OP_CONNECT,

+                        requestHandle);
                 request.setKey(key);
-            } catch (CancelledKeyException ex) {
-                // Ignore cancelled keys
             } catch (IOException ex) {
+                closeChannel(socketChannel);
                 throw new IOReactorException("Failure registering channel " +
                         "with the selector", ex);
             }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java?rev=1030045&r1=1030044&r2=1030045&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
Tue Nov  2 14:02:35 2010
@@ -187,13 +187,14 @@ public class DefaultListeningIOReactor e
             ServerSocketChannel serverChannel;
             try {
                 serverChannel = ServerSocketChannel.open();
-                serverChannel.configureBlocking(false);
             } catch (IOException ex) {
                 throw new IOReactorException("Failure opening server socket", ex);
             }
             try {
+                serverChannel.configureBlocking(false);
                 serverChannel.socket().bind(address);
             } catch (IOException ex) {
+                closeChannel(serverChannel);
                 request.failed(ex);
                 if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex)) {
                     throw new IOReactorException("Failure binding socket to address "
@@ -207,6 +208,7 @@ public class DefaultListeningIOReactor e
                 key.attach(request);
                 request.setKey(key);
             } catch (IOException ex) {
+                closeChannel(serverChannel);
                 throw new IOReactorException("Failure registering channel " +
                         "with the selector", ex);
             }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java?rev=1030045&r1=1030044&r2=1030045&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestImpl.java
Tue Nov  2 14:02:35 2010
@@ -87,6 +87,10 @@ public class SessionRequestImpl implemen
         return this.completed;
     }
 
+    protected void setKey(final SelectionKey key) {
+        this.key = key;
+    }
+
     public void waitFor() throws InterruptedException {
         if (this.completed) {
             return;
@@ -135,6 +139,16 @@ public class SessionRequestImpl implemen
             return;
         }
         this.completed = true;
+        SelectionKey key = this.key;
+        if (key != null) {
+            key.cancel();
+            Channel channel = key.channel();
+            if (channel.isOpen()) {
+                try {
+                    channel.close();
+                } catch (IOException ignore) {}
+            }
+        }
         synchronized (this) {
             this.exception = exception;
             if (this.callback != null) {
@@ -149,9 +163,10 @@ public class SessionRequestImpl implemen
             return;
         }
         this.completed = true;
-        if (this.key != null) {
-            this.key.cancel();
-            Channel channel = this.key.channel();
+        SelectionKey key = this.key;
+        if (key != null) {
+            key.cancel();
+            Channel channel = key.channel();
             if (channel.isOpen()) {
                 try {
                     channel.close();
@@ -172,24 +187,22 @@ public class SessionRequestImpl implemen
     public void setConnectTimeout(int timeout) {
         if (this.connectTimeout != timeout) {
             this.connectTimeout = timeout;
-            if (this.key != null) {
-                this.key.selector().wakeup();
+            SelectionKey key = this.key;
+            if (key != null) {
+                key.selector().wakeup();
             }
         }
     }
 
-    protected void setKey(final SelectionKey key) {
-        this.key = key;
-    }
-
     public void cancel() {
         if (this.completed) {
             return;
         }
         this.completed = true;
-        if (this.key != null) {
-            this.key.cancel();
-            Channel channel = this.key.channel();
+        SelectionKey key = this.key;
+        if (key != null) {
+            key.cancel();
+            Channel channel = key.channel();
             if (channel.isOpen()) {
                 try {
                     channel.close();



Mime
View raw message