You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Anton Khitrenovich <kh...@gmail.com> on 2008/11/11 14:12:15 UTC

Thread safety issues in org.apache.catalina.util.CookieTools

Hi all,

We are using IPlanet 6.1 web server, that is based on Catalina 4.1
container. Recently we've run into strange exceptions on Catalina level.
After examining stack trace and relevant code, I see that the problem
originates in non-synchronized usage of static SimpleDateFormat variables
from DateTool class by CookieTools.getCookieHeaderValue() function.
According to JDK documentation, "Date formats are not synchronized. It is
recommended to create separate format instances for each thread. If multiple
threads access a format concurrently, it must be synchronized externally."

Sample stack trace:

java.lang.ArrayIndexOutOfBoundsException: 466
        at
sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(BaseCalendar.java:436)
        at
java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2081)
        at
java.util.GregorianCalendar.computeFields(GregorianCalendar.java:1996)
        at java.util.Calendar.setTimeInMillis(Calendar.java:1066)
        at java.util.Calendar.setTime(Calendar.java:1032)
        at java.text.SimpleDateFormat.format(SimpleDateFormat.java:785)
        at java.text.SimpleDateFormat.format(SimpleDateFormat.java:778)
        at
org.apache.catalina.util.CookieTools.getCookieHeaderValue(CookieTools.java:150)
        at
org.apache.catalina.util.CookieTools.getCookieHeaderValue(CookieTools.java:100)
        at
com.iplanet.ias.web.connector.nsapi.NSAPIResponse.sendHeaders(NSAPIResponse.java:492)
        at
org.apache.catalina.connector.HttpResponseBase.finishResponse(HttpResponseBase.java:251)
        at
com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:180)
        at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)

Can somebody (please) confirm that there is a bug in Catalina code?

Links to relevant classes for your convenience:

*
http://svn.apache.org/repos/asf/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/util/DateTool.java
*
http://svn.apache.org/repos/asf/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/util/CookieTools.java(look
for DateTool usage)

Thanks,
    Anton.

Re: Thread safety issues in org.apache.catalina.util.CookieTools

Posted by Mark Thomas <ma...@apache.org>.
Anton Khitrenovich wrote:
> Mark,
> 
> Great, thanks!
> 
> BTW - The proposal is something official I can link to in my (future)
> conversation with Sun or just an email to somebody somewhere?

http://svn.apache.org/viewvc?view=rev&revision=713053

Two more +1 votes (and no -1s) and it will be committed to 5.5.x/4.1.x

Mark

> 
> Regards,
>     Anton.
> 
> On Tue, Nov 11, 2008 at 16:50, Mark Thomas <ma...@apache.org> wrote:
> 
>> Anton Khitrenovich wrote:
>>> Can somebody (please) confirm that there is a bug in Catalina code?
>> Yep, it is a bug. It has been fixed for 6.0.x but not proposed for back
>> porting to earlier versions.
>>
>> The fix was http://svn.apache.org/viewvc?view=rev&revision=708160
>>
>> I have just proposed it for 5.5.x. 4.1.x will pick up the changes since it
>> is in the connectors module that they both share.
>>
>> Mark
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: dev-help@tomcat.apache.org
>>
>>
> 



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


Re: Thread safety issues in org.apache.catalina.util.CookieTools

Posted by Anton Khitrenovich <kh...@gmail.com>.
Mark,

Great, thanks!

BTW - The proposal is something official I can link to in my (future)
conversation with Sun or just an email to somebody somewhere?

Regards,
    Anton.

On Tue, Nov 11, 2008 at 16:50, Mark Thomas <ma...@apache.org> wrote:

> Anton Khitrenovich wrote:
> > Can somebody (please) confirm that there is a bug in Catalina code?
> Yep, it is a bug. It has been fixed for 6.0.x but not proposed for back
> porting to earlier versions.
>
> The fix was http://svn.apache.org/viewvc?view=rev&revision=708160
>
> I have just proposed it for 5.5.x. 4.1.x will pick up the changes since it
> is in the connectors module that they both share.
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

Re: Thread safety issues in org.apache.catalina.util.CookieTools

Posted by Mark Thomas <ma...@apache.org>.
Anton Khitrenovich wrote:
> Can somebody (please) confirm that there is a bug in Catalina code?
Yep, it is a bug. It has been fixed for 6.0.x but not proposed for back
porting to earlier versions.

The fix was http://svn.apache.org/viewvc?view=rev&revision=708160

I have just proposed it for 5.5.x. 4.1.x will pick up the changes since it
is in the connectors module that they both share.

Mark


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


Re: Thread safety issues in org.apache.catalina.util.CookieTools

Posted by sebb <se...@gmail.com>.
On 11/11/2008, Anton Khitrenovich <kh...@gmail.com> wrote:
> Hi all,
>
>  We are using IPlanet 6.1 web server, that is based on Catalina 4.1
>  container. Recently we've run into strange exceptions on Catalina level.
>  After examining stack trace and relevant code, I see that the problem
>  originates in non-synchronized usage of static SimpleDateFormat variables
>  from DateTool class by CookieTools.getCookieHeaderValue() function.
>  According to JDK documentation, "Date formats are not synchronized. It is
>  recommended to create separate format instances for each thread. If multiple
>  threads access a format concurrently, it must be synchronized externally."
>

BTW, Commons LANG has a thread-safe FastDateFormat which can be used
instead of SimpleDateFormat#format(). However LANG does not have
versions of the parse() methods:

http://commons.apache.org/lang/api/org/apache/commons/lang/time/FastDateFormat.html

Might be worth considering to avoid the expense of per-thread copies
of the class.

>  Sample stack trace:
>
>  java.lang.ArrayIndexOutOfBoundsException: 466
>         at
>  sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(BaseCalendar.java:436)
>         at
>  java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2081)
>         at
>  java.util.GregorianCalendar.computeFields(GregorianCalendar.java:1996)
>         at java.util.Calendar.setTimeInMillis(Calendar.java:1066)
>         at java.util.Calendar.setTime(Calendar.java:1032)
>         at java.text.SimpleDateFormat.format(SimpleDateFormat.java:785)
>         at java.text.SimpleDateFormat.format(SimpleDateFormat.java:778)
>         at
>  org.apache.catalina.util.CookieTools.getCookieHeaderValue(CookieTools.java:150)
>         at
>  org.apache.catalina.util.CookieTools.getCookieHeaderValue(CookieTools.java:100)
>         at
>  com.iplanet.ias.web.connector.nsapi.NSAPIResponse.sendHeaders(NSAPIResponse.java:492)
>         at
>  org.apache.catalina.connector.HttpResponseBase.finishResponse(HttpResponseBase.java:251)
>         at
>  com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:180)
>         at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)
>
>  Can somebody (please) confirm that there is a bug in Catalina code?
>
>  Links to relevant classes for your convenience:
>
>  *
>  http://svn.apache.org/repos/asf/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/util/DateTool.java
>  *
>  http://svn.apache.org/repos/asf/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/util/CookieTools.java(look
>  for DateTool usage)
>
>  Thanks,
>
>     Anton.
>

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