tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arieh Markel <Arieh.Mar...@Central.Sun.COM>
Subject Re: Question: how to stop when RMI registry not available ?
Date Wed, 09 Feb 2000 00:43:08 GMT
> > However, what the behavior shows is that a ContextManager.stop() does not
> > release all the resources.
> > 
> > The TCP/IP Endpoint is still bound to the port originally allocated,
> > preventing me from doing a 'live restart'.
> > 
> > Any ideas of what is missing to be able to send the system to its 'prior to
> > webserver startup' state ?
> 
> That's another bug, TcpEndpoint.stop() is called, but it does nothing.
> 
> Probably the best solution would be to kill the listener thread, but
> that means using a deprecated and dangerous method.
> 
> Another way is to set a timeout on accept() ( since the thread is blocked
> in accept), and use the "clean" stop.

I actually managed to prevent the exceptions without mucking around with
the timeout.

Here is the context diff:

--- TcpEndpoint.java    Mon Jan 10 08:50:30 2000
+++ 
/ws/sx1.0-tools/jakarta/latest/jakarta-tomcat/src/share/org/apache/tomcat/servic
e/TcpEndpoint.java  Tue Feb  8 17:37:10 2000
@@ -1,7 +1,7 @@
 /*
- * $Header: 
/home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/service/TcpEndpoint.j
ava,v 1.4 1999/12/03 17:01:19 harishp Exp $
- * $Revision: 1.4 $
- * $Date: 1999/12/03 17:01:19 $
+ * $Header: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/TcpEndpoint.java,v 
1.6 2000/01/15 23:30:23 costin Exp $
+ * $Revision: 1.6 $
+ * $Date: 2000/01/15 23:30:23 $
  *
  * ====================================================================
  *
@@ -217,7 +217,14 @@
     
     public void stopEndpoint() {
        running=false;
-       // serverSocket.close(); XXX?
+       try
+       {
+       serverSocket.close(); // XXX?
+       }
+       catch(Exception e)
+       {
+       }
+           serverSocket = null;
     }
 
 
@@ -231,6 +238,7 @@
 
        // XXX set socket options
        //      s.setSoLinger( true, 100);
+       //      s.setSoTimeout( 1000 );
        
        TcpConnection con=new TcpConnection();
        con.setEndpoint(this);
@@ -243,11 +251,13 @@
     
     void acceptConnections() {
        try {
-           Socket socket = serverSocket.accept();
-           if (running == false) {
-               socket.close();  // rude, but unlikely!
+           if (null != serverSocket) {
+               Socket socket = serverSocket.accept();
+               if (running == false) {
+                   socket.close();  // rude, but unlikely!
+               }
+               processSocket(socket);
            }
-           processSocket(socket);
        } catch (InterruptedIOException iioe) {
            // normal part -- should happen regularly so
            // that the endpoint can release if the server
@@ -256,6 +266,14 @@
            // way for the socket to timeout without
            // tripping an exception. Exceptions are so
            // 'spensive.
+       } catch (SocketException e) {
+           if (running != false) {
+               running = false;
+               String msg = sm.getString("endpoint.err.fatal",
+                                     serverSocket, e);
+               e.printStackTrace(); // something very wrong happened - better 
know what
+               System.err.println(msg);
+           }
        } catch (Exception e) {
            running = false;
            String msg = sm.getString("endpoint.err.fatal",


The section above (catch (SocketException e)) prevents the stack trace
printing by testing against the 'running != false' which should have
been set in the 'stop()' method.

Arieh

--

I also proceeded to remove the System.exit() from ContextManager.stop().


--
 Arieh Markel		                Sun Microsystems Inc.
 Network Storage                        500 Eldorado Blvd. MS UBRM11-194
 e-mail: arieh.markel@sun.COM           Broomfield, CO 80021
 Let's go Panthers !!!!                 Phone: (303) 272-8547 x78547
 (e-mail me with subject SEND PUBLIC KEY to get public key)


Mime
View raw message