tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/startup Tomcat.java
Date Fri, 24 Mar 2000 03:29:39 GMT
craigmcc    00/03/23 19:29:39

  Modified:    src/share/org/apache/tomcat/service SimpleTcpConnector.java
                        SimpleTcpEndpoint.java
               src/share/org/apache/tomcat/service/connector
                        Ajp12ConnectionHandler.java
               src/share/org/apache/tomcat/service/http
                        HttpConnectionHandler.java
               src/share/org/apache/tomcat/startup Tomcat.java
  Log:
  Fix the "Tomcat will not shut down" problem.  There were actually two
  unrelated issues:
  
  - The logic added to the execute() method of org.apache.tomcat.startup.Tomcat
    to locate the default server configuration file also needed to be executed
    in stopTomcat().  This was causing a null pointer exception.
  
  - The server sockets on which Tomcat was listening were being given an
    accept() call to wait for the next connection, but there was no timeout
    set.  Thus, the serverSocket.close() method being called during shutdown
    was hanging "forever".  Fixed by setting the timeout.
  
  I also changed the default timeout (from 1000ms) to 5000ms, to reduce the
  CPU overhead of a relatively idle server processing timeouts.  As a result,
  it can take a worst case 5 seconds per connector to shut down (the default
  config opens two connectors, so double this) plus whatever other processing
  time is required.
  
  PR: 92
  Submitted by: Larry.Isaacs@sas.com
  
  Revision  Changes    Path
  1.3       +4 -3      jakarta-tomcat/src/share/org/apache/tomcat/service/SimpleTcpConnector.java
  
  Index: SimpleTcpConnector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/SimpleTcpConnector.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleTcpConnector.java	2000/03/20 19:34:10	1.2
  +++ SimpleTcpConnector.java	2000/03/24 03:29:37	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/SimpleTcpConnector.java,v
1.2 2000/03/20 19:34:10 costin Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/03/20 19:34:10 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/SimpleTcpConnector.java,v
1.3 2000/03/24 03:29:37 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/03/24 03:29:37 $
    *
    * ====================================================================
    *
  @@ -144,6 +144,7 @@
       }
   
       public void stop() throws Exception {
  +	cm.log("<l:stopEndpoint port=\"" + port + "\" handler=\"" + con.getClass().getName()
+ "\" />");
       	ep.stopEndpoint();
       }
   
  
  
  
  1.3       +9 -5      jakarta-tomcat/src/share/org/apache/tomcat/service/SimpleTcpEndpoint.java
  
  Index: SimpleTcpEndpoint.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/SimpleTcpEndpoint.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleTcpEndpoint.java	2000/03/20 19:34:10	1.2
  +++ SimpleTcpEndpoint.java	2000/03/24 03:29:38	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/SimpleTcpEndpoint.java,v
1.2 2000/03/20 19:34:10 costin Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/03/20 19:34:10 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/SimpleTcpEndpoint.java,v
1.3 2000/03/24 03:29:38 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/03/24 03:29:38 $
    *
    * ====================================================================
    *
  @@ -97,7 +97,7 @@
       private StringManager sm = StringManager.getManager("org.apache.tomcat.service");
   
       private static final int BACKLOG = 100;
  -    private static final int TIMEOUT = 1000;
  +    private static final int TIMEOUT = 5000;
   
       private int backlog = BACKLOG;
       private int timeout = TIMEOUT;
  @@ -169,7 +169,7 @@
        * more or less responsive to having their server sockets
        * shut down.
        *
  -     * <p>By default this value is 1000ms.
  +     * <p>By default this value is 5000ms.
        */
       public void setTimeout(int timeout) {
   	    this.timeout = timeout;
  @@ -187,6 +187,9 @@
   		} else {
   		    serverSocket = factory.createSocket(port, backlog, inet);
   		}
  +		if (serverSocket != null) {
  +		    serverSocket.setSoTimeout(this.timeout);
  +		}
   	    }
   	} catch( IOException ex ) {
   	    // throw?
  @@ -212,6 +215,7 @@
   	try {
   	    serverSocket.close(); // XXX?
   	} catch(Exception e) {
  +	    e.printStackTrace();
   	}
   	serverSocket = null;
       }
  
  
  
  1.18      +7 -0      jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java
  
  Index: Ajp12ConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Ajp12ConnectionHandler.java	2000/03/21 01:27:09	1.17
  +++ Ajp12ConnectionHandler.java	2000/03/24 03:29:38	1.18
  @@ -104,7 +104,14 @@
       public void processConnection(TcpConnection connection, Object[] theData) {
   
           try {
  +	    // XXX - Add workarounds for the fact that the underlying
  +	    // serverSocket.accept() call can now time out.  This whole
  +	    // architecture needs some serious review.
  +	    if (connection == null)
  +		return;
   	    Socket socket=connection.getSocket();
  +	    if (socket == null)
  +		return;
   	    socket.setSoLinger( true, 100);
   	    //	    socket.setSoTimeout( 1000); // or what ?
   
  
  
  
  1.17      +11 -4     jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java
  
  Index: HttpConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- HttpConnectionHandler.java	2000/03/21 23:09:44	1.16
  +++ HttpConnectionHandler.java	2000/03/24 03:29:38	1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java,v
1.16 2000/03/21 23:09:44 costin Exp $
  - * $Revision: 1.16 $
  - * $Date: 2000/03/21 23:09:44 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java,v
1.17 2000/03/24 03:29:38 craigmcc Exp $
  + * $Revision: 1.17 $
  + * $Date: 2000/03/24 03:29:38 $
    *
    * ====================================================================
    *
  @@ -105,8 +105,15 @@
   
   	//	System.out.println("New Connection");
   	try {
  +	    // XXX - Add workarounds for the fact that the underlying
  +	    // serverSocket.accept() call can now time out.  This whole
  +	    // architecture needs some serious review.
  +	    if (connection == null)
  +		return;
   	    //	    System.out.print("1");
   	    socket=connection.getSocket();
  +	    if (socket == null)
  +		return;
   	    //	    System.out.print("2");
   	    InputStream in=socket.getInputStream();
   	    OutputStream out=socket.getOutputStream();
  @@ -175,7 +182,7 @@
   	    contextM.log( "Error reading request " + e.getMessage());
   	} finally {
   	    // recycle kernel sockets ASAP
  -	    try { socket.close (); }
  +	    try { if (socket != null) socket.close (); }
   	    catch (IOException e) { /* ignore */ }
           }
   	//	System.out.print("6");
  
  
  
  1.18      +29 -24    jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java
  
  Index: Tomcat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Tomcat.java	2000/03/16 20:43:25	1.17
  +++ Tomcat.java	2000/03/24 03:29:38	1.18
  @@ -84,6 +84,32 @@
       }
       
   
  +    /**
  +     * Return the configuration file we are processing.  If the
  +     * <code>-config filename</code> command line argument is not
  +     * used, the default configuration filename will be loaded from
  +     * the TOMCAT_HOME directory.
  +     *
  +     * @param cm The ContextManager we are configuring
  +     **/
  +    File getConfigFile(ContextManager cm) {
  +
  +	// If configFile is already set, use it
  +	if (configFile != null)
  +	    return (new File(configFile));
  +
  +	// Use the "tomcat.home" property to resolve the default filename
  +	String tchome = System.getProperty("tomcat.home");
  +	if (tchome == null) {
  +	    System.out.println("No tomcat.home property, you need to set TOMCAT_HOME or add -Dtomcat.home");
  +	    tchome = ".";	// Assume current working directory
  +	}
  +	cm.setHome(tchome);
  +	return (new File(tchome, DEFAULT_CONFIG));
  +
  +    }
  +
  +
       public void execute(String args[] ) throws Exception {
   	if( ! processArgs( args ) ) {
   	    System.out.println("Wrong arguments");
  @@ -103,28 +129,8 @@
   	setHelper( xh );
   	setConnectorHelper( xh );
   	setLogHelper( xh );
  -
  -	File f;
   
  -	// - if no -f config is specified, use tomcat.home and set ContextManager.home to the
same thing.
  -	//   The user probably wants the default tomcat.
  -	// - if a config file is specified - just use it, it will probably set the contextmanager
home.
  -	if( configFile==null ) {
  -	    String tchome=System.getProperty("tomcat.home");
  -	    if( tchome == null ) {
  -		System.out.println("No tomcat.home property, you need to set TOMCAT_HOME or add -Dtomcat.home
");
  -		// try "." - a better solution would be to just exit.
  -		tchome=".";
  -	    } 
  -	    // Home will be identical to tomcat home if default config is used.
  -	    cm.setHome( tchome );
  -	    f=new File(tchome, DEFAULT_CONFIG );
  -	} else {
  -	    // config file is relative to the working directory
  -	    // if it doesn't set a home for the context manager, tomcat.home will be used
  -	    f=new File(configFile);
  -	}
  -
  +	File f = getConfigFile(cm);
   	try {
   	    xh.readXml(f,cm);
   	} catch( Exception ex ) {
  @@ -167,10 +173,9 @@
   	xh.setDebug( 0 );
   	ContextManager cm=new ContextManager();
   	setConnectorHelper( xh );
  -	// read only connector information out of server.xml
   
  -	File f=new File(cm.getHome(), configFile);
  -
  +	// read only connector information out of server.xml
  +	File f = getConfigFile(cm);
   	try {
   	    xh.readXml(f,cm);
   	} catch( Exception ex ) {
  
  
  

Mime
View raw message