Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-16316

ProducerTemplate asyncSend is not thread safe

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1.0, 3.7.2
    • Fix Version/s: 3.10.0
    • Component/s: camel-core
    • Labels:
      None
    • Estimated Complexity:
      Moderate

      Description

      The

      CompletableFuture<Exchange> asyncSend(String endpointUri, Processor processor)

      method is not thread safe because the processor is passed as a lambda to the executor service:

      getExecutorService().submit(() -> getProducerCache().asyncSendExchange(endpoint, pattern, processor,
       resultProcessor, inExchange, exchangeFuture));

      and therefore if the caller use the original Exchange reference in the Processor, for example

      request -> request.setBody(originalExchange.getIn().getBody(...))

      the executorService thread will use a dirty Exchange body in cases where the original executor thread runs faster.
      On the other hand this method is thread safe because the new Exchange object can be populated from the original exchange:

      CompletableFuture<Exchange> asyncSend(String endpointUri, Exchange exchange)

      I think the solution would be processing the request with the passed processor then submit the job to the executor service or clearly mention this in the API doc. This behavior is currently not straightforward.

      Of course you can pass references with the 2. method also which will become dirty but I think the clear intention here is sending a clean Exchange asynchronously to an endpoint with either a Processor or an exact Exchange object.

        Attachments

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              ezolnbl Zoltán Nébli
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: