Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-2835

ConcurrentModificationException in ClientImpl caused by toString-method on requestContext

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.6
    • 2.2.9
    • None
    • None

    Description

      We have about 10 threads running at the same time against the same web service. Some of the requests fail with the following stacktrace:

      javax.xml.ws.soap.SOAPFaultException: Fault string, and possibly fault code, not set
      	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146)
      	at $Proxy218.getFlightData(Unknown Source)
      	at com.example.FlightDataAction.run(FlightDataAction.java:94)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      	at java.lang.Thread.run(Thread.java:619)
      Caused by: java.util.ConcurrentModificationException
      	at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
      	at java.util.HashMap$EntryIterator.next(HashMap.java:834)
      	at java.util.HashMap$EntryIterator.next(HashMap.java:832)
      	at java.util.AbstractMap.toString(AbstractMap.java:485)
      	at java.lang.String.valueOf(String.java:2826)
      	at java.lang.StringBuilder.append(StringBuilder.java:115)
      	at java.util.AbstractMap.toString(AbstractMap.java:490)
      	at java.util.Collections$SynchronizedMap.toString(Collections.java:2026)
      	at java.lang.String.valueOf(String.java:2826)
      	at java.lang.StringBuilder.append(StringBuilder.java:115)
      	at org.apache.cxf.endpoint.ClientImpl.processResult(ClientImpl.java:535)
      	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:486)
      	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:310)
      	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:262)
      	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
      	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
      	... 5 more
      

      From ClientImpl:

          protected Map<Thread, Map<String, Object>> responseContext 
              = Collections.synchronizedMap(new WeakHashMap<Thread, Map<String, Object>>());
      ....
      
          protected Object[] processResult(Message message,
                                         Exchange exchange,
                                         BindingOperationInfo oi,
                                         Map<String, Object> resContext) throws Exception {
      ....
      
              // Grab the response objects if there are any
              List resList = null;
              Message inMsg = exchange.getInMessage();
              if (inMsg != null) {
                  if (null != resContext) {
                      resContext.putAll(inMsg);
                      if (LOG.isLoggable(Level.FINE)) {
                          LOG.fine("set responseContext to be" + responseContext);
                      }
                  }
                  resList = inMsg.getContent(List.class);
              }
      ...
      

      The use of toString on responseContext is causing a ConcurrentModificationException when there are many threads working at the same time on the same service. The LOG.fine -line is not optimal since the string is actually resolved no matter if the log line is going to be written to the log file or not. Using String.format() would fix the issue when log level is not FINE, but would not fix the actual problem caused by many threads at the same time. I'm not sure what the developer wish to log in this cause, but limiting the object traversal and not using toString should do the trick.

      Attachments

        Activity

          People

            dkulp Daniel Kulp
            henningjensen Henning Jensen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: