8000 Transaction in event listener set to rollback only gets committed · Issue #9497 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Transaction in event listener set to rollback only gets committed #9497

Closed as not planned

Description

@gitreelike

Describe the bug

Calling session.getTransactionManager().setRollbackOnly() during user creation via the admin api does not cause the transaction to get rolled back.

Version

15.1 - also present in 16.1

Expected behavior

Neither the attribute added from within the event listener nor the user should be persisted. The whole transaction should fail. Maybe there should also be a log indicating this.

Actual behavior

Instead the user gets created successfully and also an attribute set from within the event listener is persistent as well. There is no error message on the log.

How to Reproduce?

  1. Build and deploy my example event listener from here https://github.com/gitreelike/keycloak-quickstarts/blob/latest/event-listener-sysout/src/main/java/org/keycloak/quickstart/event/listener/SysoutEventListenerProvider.java
  2. Configure keycloak to use the event listener. Note: The event listener id is "sysout".
  3. Add a user via the admin console.

Anything else?

While creating a user via OIDC will not be successful this way and calling setRollbackOnly on EventType.REGISTER, and also having configured email verification - there is a NullPointerException in VerifyEMail. I'm not sure if the transaction works or doesn't work as expected in this case. At least there is transaction related log message.

Either way, I think DefaultKeycloakTransactionManager::commit really should check if the transaction is set to rollback only. Which as of my current understanding it does not do.

Also throwing an exception from within the event listener will not cause the transaction to fail. The exception is only logged. While this might be debatable I root for the EJB concept of the application exception. At least the behaviour should be documented.

Last but not least: When building the event listener as an EJB and calling ejbContext.setRollbackOnly() the transaction appears to get rolled back properly.

Activity

  1. added
    kind/bug
    on Jan 11, 2022
  2. added
    area/core
    on Jan 27, 2022
  3. mposolda commented on Mar 28, 2023

    @mposolda
    Contributor

    Preliminary adding to Backlog. We may need to triage it later.

  4. added this to the milestone on Mar 28, 2023
  5. removed this from the milestone on Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/corekind/bugteam/core-shared

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0