Coder Social home page Coder Social logo

Kafka MutinyEmitter.sendAndAwait sometimes ruins blocking DB transaction. #context-propagation, smallrye-kafka, narayana about quarkus HOT 6 OPEN

mapuci avatar mapuci commented on July 18, 2024
Kafka MutinyEmitter.sendAndAwait sometimes ruins blocking DB transaction. #context-propagation, smallrye-kafka, narayana

from quarkus.

Comments (6)

quarkus-bot avatar quarkus-bot commented on July 18, 2024

/cc @FroMage (context-propagation), @Ladicek (smallrye), @alesj (kafka), @cescoffier (kafka,mutiny), @jmartisk (smallrye), @jponge (mutiny), @manovotn (context-propagation), @ozangunalp (kafka), @phillip-kruger (smallrye), @radcortez (smallrye)

from quarkus.

ozangunalp avatar ozangunalp commented on July 18, 2024

We had a similar problem with Kafka serializer touching the managed Hibernate entity during a transaction but this one isn't it. If you remove the flush and only call persist the problem goes away. That way the entity is managed by Hibernate throughout the method calla but only persisted when the transaction is committed not before.

I don't know why flush causes the context propagation to include the Kafka sender thread inside the transaction. Maybe someone with more experience with context propagation can chime in.

from quarkus.

mapuci avatar mapuci commented on July 18, 2024

We are dealing with legacy DB, using IDENTITY id generator strategy, which causes flush on every new insert/persist :)

from quarkus.

mmusgrov avatar mmusgrov commented on July 18, 2024

I don't know what the problem is but I can comment on the symptom: You have started a transaction in one thread which then runs some code in another thread with context propagation enabled. When you commit the transaction, presumably from the first thread, the transaction manager is telling you that the second thread is still active and is running with the transaction associated.

If you don't need the second thread to run with the transaction then use your fix by clearing the transaction context, otherwise you could wait for this second thread to return before committing the transaction.

from quarkus.

mmusgrov avatar mmusgrov commented on July 18, 2024

I notice that the transaction manager is using "onePhaseCommit" which means there is only one resource involved in the transaction which I assume is the persisting of the JPA entity so it should be fine to clear the transaction context when doing the kafka call.

from quarkus.

mapuci avatar mapuci commented on July 18, 2024

I notice that the transaction manager is using "onePhaseCommit" which means there is only one resource involved in the transaction which I assume is the persisting of the JPA entity so it should be fine to clear the transaction context when doing the kafka call.

I 100% agree with everything written.
I applied the ugly fix, but still, I believe that this bug should be resolved asap.
I believe that the provided scenario is quite common. Al least in imperative world; write to db, write to kafka, wait ack, commit db tx.
And having a lib, that has 1:1000 chance of wierd failure is really not great.

While having little/no experience with reactive code and context propagation... I can only guess, what is holding the mutiny-kafka-producer thread bound to thread context after acking the message.

from quarkus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.