You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2011/07/06 12:51:19 UTC

svn commit: r1143334 - /tomcat/trunk/java/org/apache/catalina/tribes/transport/ReceiverBase.java

Author: markt
Date: Wed Jul  6 10:51:18 2011
New Revision: 1143334

URL: http://svn.apache.org/viewvc?rev=1143334&view=rev
Log:
Refactor the bind call to reduce the length of the stack traces when the unit tests fail. It probably won't fix the issue but it will make the logs easier to read.

Modified:
    tomcat/trunk/java/org/apache/catalina/tribes/transport/ReceiverBase.java

Modified: tomcat/trunk/java/org/apache/catalina/tribes/transport/ReceiverBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/transport/ReceiverBase.java?rev=1143334&r1=1143333&r2=1143334&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/transport/ReceiverBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/transport/ReceiverBase.java Wed Jul  6 10:51:18 2011
@@ -209,38 +209,36 @@ public abstract class ReceiverBase imple
     }
 
     /**
-     * recursive bind to find the next available port
-     * @param socket ServerSocket
-     * @param portstart int
-     * @param retries int
-     * @return int
+     * Attempts to bind using the provided port and if that fails attempts to
+     * bind to each of the ports from portstart to (portstart + retries -1)
+     * until either there are no more ports or the bind is successful. The
+     * address to bind to is obtained via a call to {link {@link #getBind()}.
+     * @param socket        The socket to bind
+     * @param portstart     Starting port for bind attempts
+     * @param retries       Number of times to attempt to bind (port incremented
+     *                      between attempts)
      * @throws IOException
      */
-    protected int bind(ServerSocket socket, int portstart, int retries) throws IOException {
+    protected void bind(ServerSocket socket, int portstart, int retries) throws IOException {
         InetSocketAddress addr = null;
-        while ( retries > 0 ) {
+        int port = portstart;
+        while (retries > 0) {
             try {
-                addr = new InetSocketAddress(getBind(), portstart);
+                addr = new InetSocketAddress(getBind(), port);
                 socket.bind(addr);
-                setPort(portstart);
+                setPort(port);
                 log.info("Receiver Server Socket bound to:"+addr);
-                return 0;
-            }catch ( IOException x) {
+                retries = 0;
+            } catch ( IOException x) {
                 retries--;
                 if ( retries <= 0 ) {
-                    log.info("Unable to bind server socket to:"+addr+" throwing error.");
+                    log.info("Unable to bind server socket to:" + addr +
+                            " throwing error.");
                     throw x;
                 }
-                portstart++;
-                try {
-                    Thread.sleep(25);
-                } catch (InterruptedException ti) {
-                    Thread.currentThread().interrupt();
-                }
-                retries = bind(socket,portstart,retries);
+                port++;
             }
         }
-        return retries;
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1143334 - /tomcat/trunk/java/org/apache/catalina/tribes/transport/ReceiverBase.java

Posted by Mark Thomas <ma...@apache.org>.
On 06/07/2011 12:16, Mark Thomas wrote:
> On 06/07/2011 11:51, markt@apache.org wrote:
>> Author: markt
>> Date: Wed Jul  6 10:51:18 2011
>> New Revision: 1143334
>>
>> URL: http://svn.apache.org/viewvc?rev=1143334&view=rev
>> Log:
>> Refactor the bind call to reduce the length of the stack traces when the unit tests fail. It probably won't fix the issue but it will make the logs easier to read.
> 
> Yep. It took all of 10 minutes for that to fail. I'm re-testing with a
> sync around the bind and that seems to have fixed it. I want to run
> through a few more test cycles before committing it.

Five runs through the unit tests later, the sync seems to have fixed it.
Commit following shortly.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1143334 - /tomcat/trunk/java/org/apache/catalina/tribes/transport/ReceiverBase.java

Posted by Mark Thomas <ma...@apache.org>.
On 06/07/2011 11:51, markt@apache.org wrote:
> Author: markt
> Date: Wed Jul  6 10:51:18 2011
> New Revision: 1143334
> 
> URL: http://svn.apache.org/viewvc?rev=1143334&view=rev
> Log:
> Refactor the bind call to reduce the length of the stack traces when the unit tests fail. It probably won't fix the issue but it will make the logs easier to read.

Yep. It took all of 10 minutes for that to fail. I'm re-testing with a
sync around the bind and that seems to have fixed it. I want to run
through a few more test cycles before committing it.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org