Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46875
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 25 Mar 2009 18:57:43 +0000 (18:57 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 25 Mar 2009 18:57:43 +0000 (18:57 +0000)
Add try/catch to session access in case session has been invalidated

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@758407 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/valves/CometConnectionManagerValve.java

index e277a30..c26d4e4 100644 (file)
@@ -312,8 +312,14 @@ public class CometConnectionManagerValve
                 HttpSession session = request.getSession(false);
                 if (session != null) {
                     synchronized (session) {
-                        Request[] reqs = (Request[])
-                            session.getAttribute(cometRequestsAttribute);
+                        Request[] reqs = null;
+                        try {
+                             reqs = (Request[])
+                                session.getAttribute(cometRequestsAttribute);
+                        } catch (IllegalStateException ise) {
+                            // Ignore - session has been invalidated
+                            // Listener will have cleaned up
+                        }
                         if (reqs != null) {
                             boolean found = false;
                             for (int i = 0; !found && (i < reqs.length); i++) {
@@ -329,11 +335,22 @@ public class CometConnectionManagerValve
                                             newConnectionInfos[pos++] = reqs[i];
                                         }
                                     }
-                                    session.setAttribute(cometRequestsAttribute,
-                                            newConnectionInfos);
+                                    try {
+                                        session.setAttribute(
+                                                cometRequestsAttribute,
+                                                newConnectionInfos);
+                                    } catch (IllegalStateException ise) {
+                                        // Ignore - session has been invalidated
+                                        // Listener will have cleaned up
+                                    }
                                 } else {
-                                    session.removeAttribute(
-                                            cometRequestsAttribute);
+                                    try {
+                                        session.removeAttribute(
+                                                cometRequestsAttribute);
+                                    } catch (IllegalStateException ise) {
+                                        // Ignore - session has been invalidated
+                                        // Listener will have cleaned up
+                                    }
                                 }
                             }
                         }