tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Courtney" <ja...@elementalsecurity.com>
Subject ArrayIndexOutOfBoundsException in ResourceCache.java
Date Tue, 01 Aug 2006 22:01:10 GMT
I'm pretty regularly seeing the following error in my embedded Tomcat
(5.0.28) connector.  It appears to occur as a result of one thread
entering the ResourceCache.lookup(String name) method and getting the
index of an element in the cache using the find method.  Before this
thread can access the element at that index the cache array is modified
by a second thread and the index is now outside the bounds of the array.
A basic race condition.  I've noticed that I can configure my Context
(StandardContext) to increase the max cache size which seems to help
quite a bit with this problem.  Is this the recommended solution or
should a code change also be considered to alleviate this problem?  I
would suggest that the ResourceCache.lookup method should create a
reference to the current cache which it should use rather than working
on the global cache reference which may change.  Something like this:

/* current code, ResourceCache.java line 286 */
CacheEntry cacheEntry = null;
...
int pos = find(cache, name);
/* ArrayIndexOutOfBoundsException occurs when backing array modified
between these lines */
if ((pos != -1) && (name.equals(cache[pos].name))) {
    cacheEntry = cache[pos];
}

/* new code */
CacheEntry cacheEntry = null;
CacheEntry[] currentCache = cache;
...
int pos = find(currentCache, name);
if ((pos != -1) && (name.equals(currentCache[pos].name))) {
    cacheEntry = currentCache[pos];
}

Thanks in advance for your help!

James Courtney



******************************
** The original stack trace **
******************************

2005-11-28 15:09:01: ERROR An exception or error occurred in the
container
during the request processing
java.lang.ArrayIndexOutOfBoundsException: 4868
        at
org.apache.naming.resources.ResourceCache.lookup(ResourceCache.java:288)
        at
org.apache.naming.resources.ProxyDirContext.cacheLookup(ProxyDirContext.
java:1393)
        at
org.apache.naming.resources.ProxyDirContext.lookup(ProxyDirContext.java:
279)
        at
org.apache.tomcat.util.http.mapper.Mapper.internalMapWrapper(Mapper.java
:775)
        at
org.apache.tomcat.util.http.mapper.Mapper.internalMap(Mapper.java:621)
        at
org.apache.tomcat.util.http.mapper.Mapper.map(Mapper.java:511)
        at
org.apache.coyote.tomcat5.CoyoteAdapter.postParseRequest(CoyoteAdapter.j
ava:279)
        at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:158)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79
9)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC
onnection(Http11Protocol.java:705)
        at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:57
7)
        at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool
.java:683)
        at java.lang.Thread.run(Thread.java:534)

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


Mime
View raw message