Skip to content

When receiving Kafka record request context gets incorrectly active #21367

Closed

Description

Describe the bug

When Kafka processor receives record the request context gets automatically activated. The problem is the data of RequestScope objects are not cleared.

Expected behavior

Every record received via Kafka starts with no/new request context.

Actual behavior

Every record received via Kafka uses same request context. When increasing the counter variable at the request context object the counter increases with every record. Expected behaviour would be the counter increases from zero to one for each record.

How to Reproduce?

use kafka-quickstart project

  1. create class Counter with annotation @RequestScoped
  2. create in class Counter a variable counter = 0
  3. create in class Counter method increase() which inceases and prints the counter by 1
  4. create class Worker with annotation @ApplicationScoped
  5. inject into Worker class the Counter class
  6. create in class Worker method process() with @ActivateRequestContext
  7. this process() method triggers the increase() method of the Counter class
  8. inject into QuotesProcessor class the Worker class
  9. in class QuotesProcessor in method process(String quoteRequest) trigger the method process() of class Worker

When creating new quotes via the UI and processing them in class QuotesProcessor in method process(String quoteRequest) using following comand:
Arc.container().requestContext().isActive()
you can see the request context is active, but thats wrong, he should not be active. Thats why you can see the increase of the counter in class Counter when receiving multiple quotes.

Manually deactivating and activating the context in class QuotesProcessor in method process(String quoteRequest) works:
Arc.container().requestContext().deactivate();
Arc.container().requestContext().activate();
Anyway it should work also without adding these rows.

kafka-quickstart.zip

Output of uname -a or ver

No response

Output of java -version

Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.4.1.Final

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

maven 3.6.3

Additional information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions