Bug 30489 - removeAttribute: Session already invalidated
Summary: removeAttribute: Session already invalidated
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Webapps:Manager (show other bugs)
Version: 5.0.28
Hardware: All other
: P1 critical with 1 vote (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-05 11:34 UTC by Ingolf Knopf
Modified: 2006-09-04 19:39 UTC (History)
0 users



Attachments
A patch for tomcat-5.0.28 that works around this issue (891 bytes, patch)
2005-12-16 07:37 UTC, Scott M Stark
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ingolf Knopf 2004-08-05 11:34:07 UTC
Stopping an application via Tomcat Manager, I get sometimes: "removeAttribute:
Session already invalidated" (same on Win2k and Tru64, with J2SDK 1.4.2). After
this error I must restart Tomcat.
I've never had this effect with Tomcat 4.1.24 or 5.1.19.
Stacktrace (from localhost_log....):
2004-08-05 13:22:40 StandardContext[/manager]Manager:
ManagerServlet.stop[/csc-evis-dev]
java.lang.IllegalStateException: removeAttribute: Session already invalidated
	at
org.apache.catalina.session.StandardSession.removeAttribute(StandardSession.java:1144)
	at
org.apache.catalina.session.StandardSession.removeAttribute(StandardSession.java:1119)
	at
org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1401)
	at
org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:899)
	at org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:539)
	at org.apache.catalina.session.StandardManager.unload(StandardManager.java:485)
	at org.apache.catalina.session.StandardManager.stop(StandardManager.java:687)
	at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4474)
	at
org.apache.catalina.core.StandardHostDeployer.stop(StandardHostDeployer.java:867)
	at org.apache.catalina.core.StandardHost.stop(StandardHost.java:1011)
	at org.apache.catalina.manager.ManagerServlet.stop(ManagerServlet.java:1372)
	at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:347)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
Comment 1 Igor 2004-08-05 15:10:58 UTC
I have similar problem when reloading context
(http://issues.apache.org/bugzilla/show_bug.cgi?id=29093). But I have not 
managed to provide a test case :-(
Comment 2 Yoav Shapira 2004-08-25 14:32:12 UTC
Please provide a test case if possible.  I've never had this happen before...
Comment 3 Filip Hanik 2004-08-25 15:15:28 UTC
Which version of Tomcat are you working with. this happens when the shutdown, 
the manager tries to write sessions to file, but one of the  sessions is in an 
invalid state.

Comment 4 Igor 2004-08-25 16:05:18 UTC
I use Tomcat 5.0.24. I have similar problem while reloading context. There were 
200-1000 session when this problem occured.

Unfortunately I am not able to provide a test case :-(

I think it may be related with session expiration, but I am not sure
Comment 5 Jean-Francois Arcand 2004-08-25 16:58:06 UTC
Sorry, no test case, no bug...

The Servlet TCKs test that scenario and there is no failure. Re-open the bug
once you have a test case.

Thanks

-- Jeanfrancois
Comment 6 Scott M Stark 2005-12-16 02:03:33 UTC
Here is a trace from the jboss deployer which shows why this occurs. This is the
equivalent of the tomcat manager undeploying a web app. From within the session
writeObject, the non-Serializable attributes are being removed. This in turn
causes an invalidation the session as when the removeAttribute calls isValid(),
which in turn calls expire:

expire():650, org.apache.catalina.session.StandardSession, StandardSession.java
isValid():569, org.apache.catalina.session.StandardSession, StandardSession.java
removeAttribute():1146, org.apache.catalina.session.StandardSession,
StandardSession.java
removeAttribute():1122, org.apache.catalina.session.StandardSession,
StandardSession.java
writeObject():1405, org.apache.catalina.session.StandardSession,
StandardSession.java
writeObjectData():902, org.apache.catalina.session.StandardSession,
StandardSession.java
doUnload():539, org.apache.catalina.session.StandardManager, StandardManager.java
unload():485, org.apache.catalina.session.StandardManager, StandardManager.java
stop():687, org.apache.catalina.session.StandardManager, StandardManager.java
stop():4511, org.apache.catalina.core.StandardContext, StandardContext.java
destroy():1213, org.apache.catalina.core.ContainerBase, ContainerBase.java
destroy():4617, org.apache.catalina.core.StandardContext, StandardContext.java
invoke0():-1, sun.reflect.NativeMethodAccessorImpl, NativeMethodAccessorImpl.java
invoke():39, sun.reflect.NativeMethodAccessorImpl, NativeMethodAccessorImpl.java
invoke():25, sun.reflect.DelegatingMethodAccessorImpl,
DelegatingMethodAccessorImpl.java
invoke():324, java.lang.reflect.Method, Method.java
invoke():503, org.apache.commons.modeler.BaseModelMBean, BaseModelMBean.java
invoke():109, org.jboss.mx.server.RawDynamicInvoker, RawDynamicInvoker.java
invoke():473, org.jboss.mx.server.MBeanServerImpl, MBeanServerImpl.java
performUndeployInternal():436, org.jboss.web.tomcat.tc5.TomcatDeployer,
TomcatDeployer.java

The isValid() call returns false and the remove of the non-Serializable
attribute fails:


Caused by: java.lang.IllegalStateException: removeAttribute: Session already
invalidated
        at
org.apache.catalina.session.StandardSession.removeAttribute(StandardSession.java:1147)
        at
org.apache.catalina.session.StandardSession.removeAttribute(StandardSession.java:1122)
        at
org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1405)
        at
org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:902)
        at
org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:539)
        at
org.apache.catalina.session.StandardManager.unload(StandardManager.java:485)
        at
org.apache.catalina.session.StandardManager.stop(StandardManager.java:687)
        at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4511)
        at org.apache.catalina.core.ContainerBase.destroy(ContainerBase.java:1213)
        at
org.apache.catalina.core.StandardContext.destroy(StandardContext.java:4617)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.apache.commons.modeler.BaseModelMBean.invoke(BaseModelMBean.java:503)

These stack traces are from the current jakarta-tomcat-5.0.30 beta source
release. Any attempt to serialize an expired session that has non-Serializable
attributes will show this problem.

One solution would be to not write out invalid sessions from within the
StandardManager doUnload() method.
Comment 7 Scott M Stark 2005-12-16 07:37:34 UTC
Created attachment 17231 [details]
A patch for tomcat-5.0.28 that works around this issue
Comment 8 thomas2.maesing 2006-01-16 14:59:02 UTC
The workaround doesn't fix the problem of Standard Session.

The removeAttribute method calls:

isValid()

which then expires the session if necessary:

        if (maxInactiveInterval >= 0) { 
            long timeNow = System.currentTimeMillis();
            int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L);
            if (timeIdle >= maxInactiveInterval) {
                expire(true);
            }
        }

as a result isvalid() returns false and an IllegalStateException is thrown

which results in the Context reloading again, but the StandardManager is already
in the state stopped

which results in an IllegalStateException and the Context starts reloading again
and so on


Therefore you have to stop the complete server.

I don't know the right solution, one may be a different state expired for the
StandardSession
Comment 9 Mark Thomas 2006-09-05 02:39:33 UTC
Note that this is fixed for the 5.5.x branch in 5.5.10 onwards.

I am marking this as WONTFIX since the chances of further development on the 5.0.x
branch are pretty slim.