[
https://issues.apache.org/jira/browse/WICKET-2191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12693994#action_12693994
]
Alexei Akimov commented on WICKET-2191:
---------------------------------------
Many thanks for quick response. Let's consider your fix:
Map<String, BufferedHttpServletResponse> responsesPerSession =
bufferedResponses.get(sessionId);
if (responsesPerSession == null)
{
responsesPerSession = Collections.synchronizedMap(new
MostRecentlyUsedMap<String, BufferedHttpServletResponse>(4));
bufferedResponses.put(sessionId, responsesPerSession);
}
responsesPerSession.put(bufferId, renderedResponse);
IMHO this code is not thread safe, because two concurrent threads which belong
to the same session can create two instances of responsesPerSession, but only
one instance can be put into bufferedResponses, so when the threads reach the
last line it is unknown which of them put it's renderedResponse into orphan
responsesPerSession. I sugest not to use synchronized collections but wrap
dangerous method bodies with synchronized block:
synchronized(bufferedResponses)
{
...
}
> WebApplication is not thread-safe
> ---------------------------------
>
> Key: WICKET-2191
> URL: https://issues.apache.org/jira/browse/WICKET-2191
> Project: Wicket
> Issue Type: Bug
> Components: wicket
> Affects Versions: 1.3.5, 1.4-RC2
> Environment: Microsoft Windows Server 2003 SP2, IBM WebSphere 7.0,
> Wicket 1.3.5
> Reporter: Alexei Akimov
> Assignee: Johan Compagner
> Fix For: 1.3.6, 1.4-RC3
>
>
> Instance of class org.apache.wicket.protocol.http.WebApplication is not
> thread safe being shared among several sessions. Concurrent access to it
> leads to errors because of the following:
> 1. bufferedResponses field is initialized with a simple HashMap which is not
> thread safe and can be corrupted when different threads call
> addBufferedResponse, popBufferedResponse or sessionDestroyed methods
> concurrently. Here is the stack trace:
> [27.03.09 20:55:26:669 MSK] 0000009c RequestCycle E
> org.apache.wicket.RequestCycle logRuntimeException <Null Message>
> java.util.ConcurrentModificationException
> at java.util.HashMap$AbstractMapIterator.checkConcurrentMod(Unknown
> Source)
> at java.util.HashMap$AbstractMapIterator.makeNext(Unknown Source)
> at java.util.HashMap$KeyIterator.next(Unknown Source)
> at java.util.HashMap.analyzeMap(Unknown Source)
> at java.util.HashMap.rehash(Unknown Source)
> at java.util.HashMap.rehash(Unknown Source)
> at java.util.HashMap.putImpl(Unknown Source)
> at java.util.HashMap.put(Unknown Source)
> at
> org.apache.wicket.protocol.http.WebApplication.addBufferedResponse(WebApplication.java:639)
> at
> org.apache.wicket.protocol.http.WebRequestCycle.redirectTo(WebRequestCycle.java:201)
> at
> org.apache.wicket.request.target.component.PageRequestTarget.respond(PageRequestTarget.java:58)
> at
> org.apache.wicket.request.AbstractRequestCycleProcessor.respond(AbstractRequestCycleProcessor.java:104)
> at
> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1181)
> at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252)
> at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353)
> at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
> at
> org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355)
> at
> org.apache.wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:145)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
> at
> com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1443)
> at
> com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1384)
> at
> com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
> 2. Class org.apache.wicket.util.collections.MostRecentlyUsedMap is not
> thread-safe and can be courrupted when different threads call
> addBufferedResponse, popBufferedResponse concurrently.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.