larryi 00/12/14 19:43:43
Modified: src/facade22/org/apache/tomcat/facade ServletHandler.java
Log:
Synchronize setting of data for UnavailableException thrown from service().
An UnavailableException returning a getUnavailableSeconds() = 0 could
be expired out from under the request trying to set it if another request
came in with just the right timing.
We may want to set a minimum unavailable time. If we keep setting and
expiring an UnavailableException that returns getUnavailableSeconds() = 0,
we could end up synchronizing a lot.
A few additional corrections to get UnavailableException working as
expected.
Error handling still needs updating so that UnavailableExceptions
return a status code of 503 instead of 500.
Revision Changes Path
1.6 +16 -10
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java
Index: ServletHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServletHandler.java 2000/12/15 00:02:12 1.5
+++ ServletHandler.java 2000/12/15 03:43:43 1.6
@@ -180,6 +180,9 @@
errorException = null;
return;// already destroyed or not init.
}
+ // XXX if we are being destroyed due to permanent UnavailableException
+ // thrown in service(), we probably don't want to go to ADDED state.
+ // may need a STATE_DISABLE_PERM?
setState( STATE_ADDED );
// XXX post will not be called if any error happens in destroy.
@@ -277,7 +280,7 @@
// if no error happened and if doInit didn't put us in
// a special state, we are ready
if( state!=STATE_DISABLED &&
- getErrorException() != null ) {
+ getErrorException() == null ) {
state=STATE_READY;
}
}
@@ -370,10 +373,12 @@
// Deal with Unavailable errors
if( ! checkAvailable() ) {
- // init can't proceed
- setState( STATE_DELAYED_INIT );
+ // remain in STATE_DELAYED_INIT state
return;
}
+
+ // clear STATE_DELAYED_INIT if set
+ setState( STATE_ADDED );
// For JSPs we rely on JspInterceptor to set the servlet class name.
// We make no distinction between servlets and jsps.
@@ -397,9 +402,7 @@
setServletUnavailable( ex );
}
servlet=null;
- throw ex;
- // it's a normal exception, servlet will
- // not be initialized.
+ // we have set the exception and state, okay to just return
}
// other exceptions are just thrown -
@@ -489,14 +492,17 @@
} catch ( UnavailableException ex ) {
if ( ex.isPermanent() ) {
setState( STATE_DISABLED );
- } else {
- setServletUnavailable((UnavailableException)ex );
+ // XXX spec says we must destroy the servlet
}
if ( null != getErrorException() ) {
synchronized(this) {
if ( null!= getErrorException() ) {
- // servlet exception state
- setErrorException( ex );
+ if ( state == STATE_DISABLED )
+ // servlet exception state
+ setErrorException( ex );
+ else
+ // set expiration
+ setServletUnavailable((UnavailableException)ex );
}
}
}