Antony Stubbs created KAFKA-10382:
-------------------------------------

             Summary: MockProducer is not ThreadSafe, ideally it should be as 
the implementation it mocks is
                 Key: KAFKA-10382
                 URL: https://issues.apache.org/jira/browse/KAFKA-10382
             Project: Kafka
          Issue Type: Bug
          Components: clients
    Affects Versions: 2.6.0
            Reporter: Antony Stubbs


In testing my project, I discovered that the MockProducer is not thread safe as 
I thought. It doesn't use thread safe libraries for it's underlying stores, and 
only _some_ of it’s methods are synchronised.

 

As performance isn’t an issue for this, I would propose simply synchronising 
all public methods in the class, as some already are.

 

In my project, send is synchronised and commit transactions isn’t. This was 
causing weird collection manipulation and messages going missing. My lolcat 
only solution was simply to synchronise on the MockProducer instance before 
calling commit.

 

See my workaround: 
https://github.com/astubbs/async-consumer/pull/13/files#diff-8e93aa2a2003be7436f94956cf809b2eR558

 

PR available: https://github.com/apache/kafka/pull/9154



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to