Bug 48790 - Race condition in org.apache.catalina.session.ManagerBase:maxActive
Summary: Race condition in org.apache.catalina.session.ManagerBase:maxActive
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.18
Hardware: All All
: P2 major (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-22 03:41 UTC by Yao Qi
Modified: 2010-04-11 09:49 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yao Qi 2010-02-22 03:41:21 UTC
We are running tomcat 6.0.18 with a race detector (http://www.alphaworks.ibm.com/tech/msdk), and find one race condition in class 
org.apache.catalina.session.ManagerBase field maxActive.

Data Race 1 : org.apache.catalina.session.ManagerBase : maxActive

  Thread "http-8080-3" : Tid 34 : WRITE
        Lock Set : [ ]
      [org.apache.catalina.session.ManagerBase : add(Lorg/apache/catalina/Session;)V :  : 741]
      [org.apache.catalina.session.StandardSession : setId(Ljava/lang/String;)V :  : 368]
      [org.apache.catalina.session.ManagerBase : createSession(Ljava/lang/String;)Lorg/apache/catalina/Session; :  : 827]
      [org.apache.catalina.session.StandardManager : createSession(Ljava/lang/String;)Lorg/apache/catalina/Session; :  : 291]
      [org.apache.catalina.connector.Request : doGetSession(Z)Lorg/apache/catalina/Session; :  : 2324]
      [org.apache.catalina.connector.Request : getSession(Z)Ljavax/servlet/http/HttpSession; :  : 2074]
      [org.apache.catalina.connector.RequestFacade : getSession(Z)Ljavax/servlet/http/HttpSession; :  : 833]
      [org.apache.catalina.connector.RequestFacade : getSession()Ljavax/servlet/http/HttpSession; :  : 844]
      [com.ecyrd.jspwiki.auth.AuthenticationManager : login(Ljavax/servlet/http/HttpServletRequest;)Z :  : 270]
........
  Thread "http-8080-1" : Tid 32 : READ
        Lock Set : [ ]
      [org.apache.catalina.session.ManagerBase : add(Lorg/apache/catalina/Session;)V :  : 740]
      [org.apache.catalina.session.StandardSession : setId(Ljava/lang/String;)V :  : 368]
      [org.apache.catalina.session.ManagerBase : createSession(Ljava/lang/String;)Lorg/apache/catalina/Session; :  : 827]
      [org.apache.catalina.session.StandardManager : createSession(Ljava/lang/String;)Lorg/apache/catalina/Session; :  : 291]
........

Here is the code snip of ManagerBase.java

    public void add(Session session) {

        sessions.put(session.getIdInternal(), session);
        int size = sessions.size();
1->      if( size > maxActive ) {
2->         maxActive = size;
        }
    }

Statement 1 and statement 2 should executed in an atomic manner.  One fix to this problem is to move statement 1 and statement 2 into a synchronized block.
Comment 1 Mark Thomas 2010-03-09 22:23:07 UTC
Fixed in trunk and proposed for 6.0.x.

I came very close to marking this as WONTFIX because I don't think the thread safety issues are going to cause any harm.
Comment 2 Yao Qi 2010-03-10 01:22:50 UTC
(In reply to comment #1)
> Fixed in trunk and proposed for 6.0.x.
> 

I'll go to trunk and have a look.

> I came very close to marking this as WONTFIX because I don't think the thread
> safety issues are going to cause any harm.
Right, the boundary of harmful race and benign race is not very clear.
Comment 3 Mark Thomas 2010-04-11 09:49:24 UTC
This has been fixed in 6.0.x and will be included in 6.0.27 onwards.