Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-10382

MockProducer is not ThreadSafe, ideally it should be as the implementation it mocks is

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.6.0
    • None
    • clients
    • None

    Description

      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

      Attachments

        Activity

          People

            Unassigned Unassigned
            astubbs Antony Stubbs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: