Race condition in AbstractCachingProcessingPipeline causes threads to hang.
---------------------------------------------------------------------------

                 Key: COCOON-2208
                 URL: https://issues.apache.org/jira/browse/COCOON-2208
             Project: Cocoon
          Issue Type: Bug
          Components: * Cocoon Core
    Affects Versions: 2.1.11
            Reporter: Sylvain Wallez
            Priority: Blocker


There's a race condition in AbstractCachingProcessingPipeline.waitForLock() : 
if "lock" is not null, there is a possibility that the thread that created the 
lock releases it before the current thread starts waiting on it (see below). 
When this happens, the thread waits forever since no thread will ever call 
notify() on the lock.

The very bad effect is that this progressively blocks the entire thread pool of 
the servlet engine, which ends up rejecting new incoming connections.

And BTW, calling containsKey() just before get() unneedingly doubles the number 
of lookups.

{noformat}
    protected boolean waitForLock(Object key) {
        if(transientStore != null) {
                Object lock = null;
                synchronized(transientStore) {
                        String lockKey = PIPELOCK_PREFIX+key;
                        if(transientStore.containsKey(lockKey)) {
                        // cache content is currently being generated, wait for 
other thread
                        lock = transientStore.get(lockKey);
                        }
                }
// START OF RACE CONDITION ZONE
                if(lock != null) {
                        try {
                                // become owner of monitor
                                synchronized(lock) {
// END OF RACE CONDITION ZONE
                                        lock.wait();
                                }
                        } catch (InterruptedException e) {
                                if(getLogger().isDebugEnabled()) {
                                        getLogger().debug("Got interrupted 
waiting for other pipeline to finish processing, retrying...",e);
                                }
                                return false;
                                }
                        if(getLogger().isDebugEnabled()) {
                                getLogger().debug("Other pipeline finished 
processing, retrying to get cached response.");
                        }
                        return false;
                }
        }
        return true;
    }
{noformat}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to