ASF Bugzilla – Attachment 27654 Details for
Bug 51919
Random ConcurrentModificationException or NoSuchElementException in CookieManager#removeMatchingCookies when using Concurrent Download
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Fix to issue
BUG_51919.patch (text/plain), 6.16 KB, created by
Philippe Mouawad
on 2011-10-01 09:51:48 UTC
(
hide
)
Description:
Fix to issue
Filename:
MIME Type:
Creator:
Philippe Mouawad
Created:
2011-10-01 09:51:48 UTC
Size:
6.16 KB
patch
obsolete
>Index: src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java >=================================================================== >--- src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java (revision 1177675) >+++ src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java (working copy) >@@ -30,6 +30,7 @@ > import java.net.URL; > import java.util.ArrayList; > import java.util.Date; >+import java.util.concurrent.locks.ReentrantLock; > > import org.apache.commons.httpclient.cookie.CookiePolicy; > import org.apache.commons.httpclient.cookie.CookieSpec; >@@ -101,6 +102,10 @@ > > public static final String DEFAULT_POLICY = CookiePolicy.BROWSER_COMPATIBILITY; > >+ private final ReentrantLock CONTEXT_VARIABLES_LOCK = new ReentrantLock(); >+ >+ private final ReentrantLock COOKIE_MANAGER_UPDATE_LOCK = new ReentrantLock(); >+ > public CookieManager() { > clearCookies(); // Ensure that there is always a collection available > } >@@ -153,6 +158,7 @@ > writer.println("# JMeter generated Cookie file");// $NON-NLS-1$ > PropertyIterator cookies = getCookies().iterator(); > long now = System.currentTimeMillis(); >+ // No need for sync as not called during test plan > while (cookies.hasNext()) { > Cookie cook = (Cookie) cookies.next().getObjectValue(); > final long expiresMillis = cook.getExpiresMillis(); >@@ -183,6 +189,7 @@ > // N.B. this must agree with the save() and cookieToString() methods > String line; > try { >+ // No need for sync as not called during load test > final CollectionProperty cookies = getCookies(); > while ((line = reader.readLine()) != null) { > try { >@@ -265,11 +272,24 @@ > if (log.isDebugEnabled()) { > log.debug("Add cookie to store " + c.toString()); > } >- getCookies().addItem(c); >+ try { >+ COOKIE_MANAGER_UPDATE_LOCK.lock(); >+ getCookies().addItem(c); >+ } finally { >+ COOKIE_MANAGER_UPDATE_LOCK.unlock(); >+ } > if (SAVE_COOKIES) { > JMeterContext context = getThreadContext(); > if (context.isSamplingStarted()) { >- context.getVariables().put(COOKIE_NAME_PREFIX+cn, cv); >+ try { >+ // If we do not sync Map inside Variables might be corrupted, >+ // note that this may happen from other callers (as initially >+ // JMeterVariables are not supposed to be shared >+ CONTEXT_VARIABLES_LOCK.lock(); >+ context.getVariables().put(COOKIE_NAME_PREFIX+cn, cv); >+ } finally { >+ CONTEXT_VARIABLES_LOCK.unlock(); >+ } > } > } > } >@@ -332,20 +352,26 @@ > * > */ > public org.apache.commons.httpclient.Cookie[] getCookiesForUrl(URL url){ >- CollectionProperty jar=getCookies(); >- org.apache.commons.httpclient.Cookie cookies[]= >- new org.apache.commons.httpclient.Cookie[jar.size()]; >- int i=0; >- for (PropertyIterator iter = getCookies().iterator(); iter.hasNext();) { >- Cookie jmcookie = (Cookie) iter.next().getObjectValue(); >- // Set to running version, to allow function evaluation for the cookie values (bug 28715) >- if (ALLOW_VARIABLE_COOKIES) { >- jmcookie.setRunningVersion(true); >- } >- cookies[i++] = makeCookie(jmcookie); >- if (ALLOW_VARIABLE_COOKIES) { >- jmcookie.setRunningVersion(false); >+ org.apache.commons.httpclient.Cookie[] cookies= null; >+ try { >+ COOKIE_MANAGER_UPDATE_LOCK.lock(); >+ CollectionProperty jar=getCookies(); >+ cookies = >+ new org.apache.commons.httpclient.Cookie[jar.size()]; >+ int i=0; >+ for (PropertyIterator iter = getCookies().iterator(); iter.hasNext();) { >+ Cookie jmcookie = (Cookie) iter.next().getObjectValue(); >+ // Set to running version, to allow function evaluation for the cookie values (bug 28715) >+ if (ALLOW_VARIABLE_COOKIES) { >+ jmcookie.setRunningVersion(true); >+ } >+ cookies[i++] = makeCookie(jmcookie); >+ if (ALLOW_VARIABLE_COOKIES) { >+ jmcookie.setRunningVersion(false); >+ } > } >+ } finally { >+ COOKIE_MANAGER_UPDATE_LOCK.unlock(); > } > String host = url.getHost(); > String protocol = url.getProtocol(); >@@ -461,19 +487,24 @@ > > private void removeMatchingCookies(Cookie newCookie){ > // Scan for any matching cookies >- PropertyIterator iter = getCookies().iterator(); >- while (iter.hasNext()) { >- Cookie cookie = (Cookie) iter.next().getObjectValue(); >- if (cookie == null) {// TODO is this possible? >- continue; >- } >- if (match(cookie,newCookie)) { >- if (log.isDebugEnabled()) { >- log.debug("New Cookie = " + newCookie.toString() >- + " removing matching Cookie " + cookie.toString()); >+ try { >+ COOKIE_MANAGER_UPDATE_LOCK.lock(); >+ PropertyIterator iter = getCookies().iterator(); >+ while (iter.hasNext()) { >+ Cookie cookie = (Cookie) iter.next().getObjectValue(); >+ if (cookie == null) {// TODO is this possible? >+ continue; > } >- iter.remove(); >- } >+ if (match(cookie,newCookie)) { >+ if (log.isDebugEnabled()) { >+ log.debug("New Cookie = " + newCookie.toString() >+ + " removing matching Cookie " + cookie.toString()); >+ } >+ iter.remove(); >+ } >+ } >+ } finally { >+ COOKIE_MANAGER_UPDATE_LOCK.unlock(); > } > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 51919
:
27636
|
27643
|
27654
|
27656
|
27657
|
27716