question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mutiny.Session.withTransaction(...) needs duplicated context

See original GitHub issue

Describe the bug

I am trying to run task with @Scheduled:

    @Scheduled(every = "PT5S")
    fun start2() {
        var setting = vertx.executeBlocking<Setting> {
            sf.withTransaction { sess ->  sess.find(Setting::class.java, "test")} 
                .await()
                .atMost(Duration.ofSeconds(2))
        }
        setting.onSuccess { logger.info { it } }
            .onFailure { logger.error(it) { it } }
    }

And get error about duplicated context needed: java.lang.IllegalStateException: Can't get the context safety flag: the current context is not a duplicated context

I’m tryed also with no result

    @Scheduled(every = "PT5S")
    fun start2() {
        var setting = vertx.executeBlocking<Setting> {
            sf.withSession { session -> sf.withTransaction { sess ->  sess.find(Setting::class.java, "test")} }
                .await()
                .atMost(Duration.ofSeconds(2))
        }
        setting.onSuccess { logger.info { it } }
            .onFailure { logger.error(it) { it } }
    }

Without vertx.executeBlocking<Setting> {} I get error: The current operation requires a safe (isolated) Vert.x sub-context, but the current context hasn't been flagged as such. You can still use Hibernate Reactive, you just need to avoid using the methods which implicitly require accessing the stateful context, such as MutinySessionFactory#withTransaction and #withSession.

Expected behavior

Mutiy.Session.withTransaction(…) works fine in scheduler

Actual behavior

Error: java.lang.IllegalStateException: Can't get the context safety flag: the current context is not a duplicated context

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

jdk 17.0.2

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.7.5 and 2.8.0

Build tool (ie. output of mvnw --version or gradlew --version)

gradle 7.4.1

Additional information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
cescoffiercommented, Apr 15, 2022

no, but it may need 2.9 (main branch)

0reactions
cescoffiercommented, May 1, 2022

#25257 has been fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quarkus 2.9.0.CR1: Async Scheduled methods have ... - GitHub
Not all components require the duplicated context, or? The main issue is that the context put/get methods are public API of Vert.x -...
Read more >
Mutiny.SessionFactory: use existing session for saving entities
In your case, if you want to merge two entities using the same session, you need to make sure that the operations happen...
Read more >
Apache Kafka Reference Guide - Quarkus
However, not committing the offset often enough may lead to message duplication if the application crashes between two commits. The Kafka connector supports ......
Read more >
Microservices | Programmatic Ponderings
Mutiny can be used in any Java application exhibiting asynchrony, ... method was enclosed in a call to Mutiny.Session.withTransaction(java.util.function.
Read more >
Hibernate Reactive 1.0.3.Final Reference Documentation
You'll also need to add a dependency for the Vert.x reactive database driver ... Mutiny.Session and friends provide an API based on Mutiny....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found