Skip to content

LDAP group synchronization hangs indefinitely when Batch Size for Sync is set to 0 #55311

Description

@ValkoinenKissa

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

ldap

Bug Description

When configuring an LDAP User Federation provider with a group-ldap-mapper, setting Batch Size for Sync to 0 causes group synchronization to enter an infinite loop.

The synchronization process does not make progress and eventually triggers transaction timeouts.

The issue was observed with Keycloak 26.8.2 using Samba Active Directory over LDAPS.

Version

26.8.2

Regression

  • The issue is a regression

Expected behavior

Keycloak should handle a batch size of 0 safely.

If zero is not a supported value, the configuration should be rejected with a clear validation error instead of allowing synchronization to enter an infinite loop.

Actual behavior

When Batch Size for Sync is set to 0, LDAP group synchronization does not make progress and enters an infinite loop.

The transaction manager eventually detects long-running transactions and cancels them. This results in transaction rollback errors and Hibernate exceptions.

The issue prevents the group mapper synchronization from completing successfully.

How to Reproduce?

  1. Start Keycloak 26.8.2.
  2. Configure an LDAP User Federation provider connected to an Active Directory server.
  3. Configure a group-ldap-mapper for the LDAP provider.
  4. Set the LDAP provider's Batch Size for Sync to 0.
  5. Trigger synchronization of the LDAP group mapper.
  6. Observe that synchronization does not complete and transaction timeouts eventually occur.

Tested environment:

  • Keycloak: 26.8.2
  • LDAP vendor: Active Directory (Samba AD)
  • Connection: LDAPS
  • Mapper: group-ldap-mapper
  • Mode: READ_ONLY
  • User Groups Retrieve Strategy: GET_GROUPS_FROM_USER_MEMBEROF_ATTRIBUTE

Anything else?

Workaround

Setting the LDAP provider's Batch Size for Sync to 100 resolves the issue in our environment.

Technical investigation

The issue appears to originate in GroupLDAPStorageMapper.java, specifically in syncFlatGroupStructure().

The outer iterator loop checks whether more groups are available, while iterator advancement occurs inside an inner loop controlled by groupsPerTransaction.

When groupsPerTransaction is 0, the inner loop never executes and the iterator is never advanced. Consequently, the outer loop cannot terminate.

Relevant source code (Keycloak 26.8.2):

https://github.com/keycloak/keycloak/blob/26.8.2/federation/ldap/src/main/java/org/keycloak/storage/ldap/mappers/membership/group/GroupLDAPStorageMapper.java

Transaction manager and Hibernate logs

The following messages were observed during synchronization:

ARJUNA012117: TransactionReaper::check processing TX ... in state RUN

ARJUNA012404: Action id ... had stackTrace
    ...
    GroupLDAPStorageMapper.syncFlatGroupStructure(GroupLDAPStorageMapper.java:266)
    GroupLDAPStorageMapper.syncDataFromFederationProviderToKeycloak(GroupLDAPStorageMapper.java:191)
    UserStorageProviderResource.syncMapperData(UserStorageProviderResource.java:259)

HHH90007020: Transaction afterCompletion called by a background thread;
delaying afterCompletion processing until the original thread can handle it.

ARJUNA012095: Abort of action invoked while multiple threads active within it.

ARJUNA012108: CheckedAction::check - atomic action aborting with 1 threads active!

ARJUNA012121: TransactionReaper::doCancellations worker successfully canceled TX

After Keycloak shutdown, additional Hibernate errors appeared:

org.hibernate.HibernateException:
Transaction was rolled back in a different thread

The associated exception was raised while closing the JPA connection provider:

org.keycloak.connections.jpa.DefaultJpaConnectionProvider.close
org.keycloak.services.DefaultKeycloakSession.close

These Hibernate exceptions appear to be consequences of the transaction being rolled back by the Transaction Reaper in another thread, rather than the original cause of the synchronization failure.

Activity

  1. added
    kind/bug
    on Nov 18, 2026
  2. added
    area/ldap
    on Nov 18, 2026
  3. self-assigned this
    on Nov 20, 2026
  4. tkyjovsk commented on Nov 23, 2026

    @tkyjovsk
    Contributor

    The 26.8.2 code supports the reported cause: with batch size zero, flat group synchronization never advances its iterator when LDAP groups are present. (Also affects 26.4 so it's not a recent regression; and the current main.)

    PR #55334 addresses the problem and includes a reported reproduction against ApacheDS. Zero already selects non-paginated loading elsewhere in the LDAP implementation, I'd say it makes sense to go with the same behavior for consistency.

  5. keycloak-github-bot commented on Nov 23, 2026

    @keycloak-github-bot

    Due to the amount of issues reported by the community we are not able to prioritise resolving this issue at the moment.

    If you are affected by this issue, upvote it by adding a 👍 to the description. We would also welcome a contribution to fix the issue.

  6. removed their assignment
    on Nov 23, 2026
  7. added 2 commits that reference this issue on Nov 27, 2026
    12e4698
    2416dba
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/ldaphelp wantedkind/bugpriority/normalstatus/auto-bumpstatus/auto-expireteam/core-iam

    Type

    Fields

    No fields configured for bug.

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions