tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Ericsson <jakob.erics...@gmail.com>
Subject session.isNew() not thread safe?
Date Thu, 26 Feb 2009 16:03:44 GMT
Hello,

We are experiencing some thread/race condition problems with
HttpSession isNew() for Tomcat 6 (specifically for 6.0.18 but we have
seen the problem in prior versions too).
We narrowed it down to a small example.

The flow is quite simple.

1. Request first.jsp
2. Request second.jsp

Randomly we get the text "This should not happen, the session should
not be new on this page" printed out.
We are using jMeter to generate load, running 150 concurrent users.

Page first.jsp:
---------------------
<%
    session.setAttribute("sessionTest", "test");
%>
<html>
  <head><title>Session is New Test</title></head>
  <body>Page one sets a value one the session.</body>
</html>
---------------------

Page second.jsp:
---------------------
<%
    boolean newSession = false;
    if (session.isNew()) {
        if (session.getAttribute("sessionTest") != null) {
            newSession = true;
            System.out.println("This should not happen, the session
should not be new on this page.");
        }
    }
%>
<html>
  <head><title>Session is New Test</title></head>
  <body>Page to two the session should not be new, isNew =
<%=newSession%></body>
</html>
---------------------

Our feeling is that this is a race condition between threads before
tomcat set isNew to false.
A quick workaround is to use request.getSession(false) and null
checks. This seems to get us around our specific application problem.

Could this be a problem in Tomcat?

Regards,
Jakob Ericsson

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message