<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px"><div id="yui_3_16_0_1_1457385763000_2970" class="">Hi,</div><div id="yui_3_16_0_1_1457385763000_2972" class="">i wrote my custom federation provider.</div><div id="yui_3_16_0_1_1457385763000_2974" class="">All the synchronize operations (roles and user-roles) are done inside the getUserByUsername and the isValid method.</div><div id="yui_3_16_0_1_1457385763000_2976" class="">This way every time a user or a new-user logins into my system, all the roles and role-mapping are kept up to date.</div><div id="yui_3_16_0_1_1457385763000_2978" class="">All seems to work well with one user, but now i'm experiencing a lot of exceptions in a concurrence environment.</div><div id="yui_3_16_0_1_1457385763000_2980" class="">These are the tests i'm launching:</div><div id="yui_3_16_0_1_1457385763000_2982" class="">1) 20 concurrent threads, each of which tries to login, to send a REST request (to backend) and finally to logout. All 20 threads login with the same test username.</div><div id="yui_3_16_0_1_1457385763000_2984" class="">2) 200 concurrent threads, doing the same as at the previous point, with 20 differents username.</div><div id="yui_3_16_0_1_1457385763000_2986" class=""><br id="yui_3_16_0_1_1457385763000_2988" class=""></div><div id="yui_3_16_0_1_1457385763000_2990" class="">Everytime each federation provider instance tries to synchronize all realm roles...adding or removing roles in concurrence, i catch this error:</div><div id="yui_3_16_0_1_1457385763000_2992" class=""><br id="yui_3_16_0_1_1457385763000_2994" class=""></div><div id="yui_3_16_0_1_1457385763000_2996" class=""><br id="yui_3_16_0_1_1457385763000_2998" class=""></div><div id="yui_3_16_0_1_1457385763000_3000" class="">16:10:08,228 ERROR [io.undertow.request] (default task-96) UT005023: Exception handling request to /auth/realms/MyRealm/protocol/openid-connect/token: java.lang.RuntimeException: reques</div><div id="yui_3_16_0_1_1457385763000_3002" class="">t path: /auth/realms/MyRealm/protocol/openid-connect/token</div><div id="yui_3_16_0_1_1457385763000_3004" class=""> at org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:75)</div><div id="yui_3_16_0_1_1457385763000_3006" class=""> at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)</div><div id="yui_3_16_0_1_1457385763000_3008" class=""> at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)</div><div id="yui_3_16_0_1_1457385763000_3010" class=""> at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)</div><div id="yui_3_16_0_1_1457385763000_3012" class=""> at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)</div><div id="yui_3_16_0_1_1457385763000_3014" class=""> at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)</div><div id="yui_3_16_0_1_1457385763000_3016" class=""> at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)</div><div id="yui_3_16_0_1_1457385763000_3018" class=""> at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div id="yui_3_16_0_1_1457385763000_3020" class=""> at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)</div><div id="yui_3_16_0_1_1457385763000_3022" class=""> at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)</div><div id="yui_3_16_0_1_1457385763000_3024" class=""> at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div id="yui_3_16_0_1_1457385763000_3026" class=""> at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)</div><div id="yui_3_16_0_1_1457385763000_3028" class=""> at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)</div><div id="yui_3_16_0_1_1457385763000_3030" class=""> at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)</div><div id="yui_3_16_0_1_1457385763000_3032" class=""> at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)</div><div id="yui_3_16_0_1_1457385763000_3034" class=""> at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)</div><div id="yui_3_16_0_1_1457385763000_3036" class=""> at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)</div><div id="yui_3_16_0_1_1457385763000_3038" class=""> at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div id="yui_3_16_0_1_1457385763000_3040" class=""> at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)</div><div id="yui_3_16_0_1_1457385763000_3042" class=""> at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div id="yui_3_16_0_1_1457385763000_3044" class=""> at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div id="yui_3_16_0_1_1457385763000_3046" class=""> at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)</div><div id="yui_3_16_0_1_1457385763000_3048" class=""> at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)</div><div id="yui_3_16_0_1_1457385763000_3050" class=""> at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)</div><div id="yui_3_16_0_1_1457385763000_3052" class=""> at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)</div><div id="yui_3_16_0_1_1457385763000_3054" class=""> at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)</div><div id="yui_3_16_0_1_1457385763000_3056" class=""> at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)</div><div id="yui_3_16_0_1_1457385763000_3058" class=""> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)</div><div id="yui_3_16_0_1_1457385763000_3060" class=""> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)</div><div id="yui_3_16_0_1_1457385763000_3062" class=""> at java.lang.Thread.run(Thread.java:745)</div><div id="yui_3_16_0_1_1457385763000_3064" class="">Caused by: org.jboss.resteasy.spi.UnhandledException: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection</div><div id="yui_3_16_0_1_1457385763000_3066" class=""> at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)</div><div id="yui_3_16_0_1_1457385763000_3068" class=""> at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)</div><div id="yui_3_16_0_1_1457385763000_3070" class=""> at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)</div><div id="yui_3_16_0_1_1457385763000_3072" class=""> at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)</div><div id="yui_3_16_0_1_1457385763000_3074" class=""> at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)</div><div id="yui_3_16_0_1_1457385763000_3076" class=""> at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)</div><div id="yui_3_16_0_1_1457385763000_3078" class=""> at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)</div><div id="yui_3_16_0_1_1457385763000_3080" class=""> at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)</div><div id="yui_3_16_0_1_1457385763000_3082" class=""> at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)</div><div id="yui_3_16_0_1_1457385763000_3084" class=""> at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)</div><div id="yui_3_16_0_1_1457385763000_3086" class=""> at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)</div><div id="yui_3_16_0_1_1457385763000_3088" class=""> at org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:61)</div><div id="yui_3_16_0_1_1457385763000_3090" class=""> ... 29 more</div><div id="yui_3_16_0_1_1457385763000_3092" class="">Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection</div><div id="yui_3_16_0_1_1457385763000_3094" class=""> at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)</div><div id="yui_3_16_0_1_1457385763000_3096" class=""> at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)</div><div id="yui_3_16_0_1_1457385763000_3098" class=""> at org.hibernate.jpa.spi.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1771)</div><div id="yui_3_16_0_1_1457385763000_3100" class=""> at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:64)</div><div id="yui_3_16_0_1_1457385763000_3102" class=""> at org.keycloak.connections.jpa.JpaKeycloakTransaction.begin(JpaKeycloakTransaction.java:22)</div><div id="yui_3_16_0_1_1457385763000_3104" class=""> at org.keycloak.services.DefaultKeycloakTransactionManager.enlist(DefaultKeycloakTransactionManager.java:25)</div><div id="yui_3_16_0_1_1457385763000_3106" class=""> at org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.create(DefaultJpaConnectionProviderFactory.java:46)</div><div id="yui_3_16_0_1_1457385763000_3108" class=""> at org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.create(DefaultJpaConnectionProviderFactory.java:30)</div><div id="yui_3_16_0_1_1457385763000_3110" class=""> at org.keycloak.services.DefaultKeycloakSession.getProvider(DefaultKeycloakSession.java:103)</div><div id="yui_3_16_0_1_1457385763000_3112" class=""> at org.keycloak.models.jpa.JpaUserProviderFactory.create(JpaUserProviderFactory.java:34)</div><div id="yui_3_16_0_1_1457385763000_3114" class=""> at org.keycloak.models.jpa.JpaUserProviderFactory.create(JpaUserProviderFactory.java:16)</div><div id="yui_3_16_0_1_1457385763000_3116" class=""> at org.keycloak.services.DefaultKeycloakSession.getProvider(DefaultKeycloakSession.java:103)</div><div id="yui_3_16_0_1_1457385763000_3118" class=""> at org.keycloak.models.cache.infinispan.DefaultCacheUserProvider.getDelegate(DefaultCacheUserProvider.java:50)</div><div id="yui_3_16_0_1_1457385763000_3120" class=""> at org.keycloak.models.cache.infinispan.DefaultCacheUserProvider.getUserByUsername(DefaultCacheUserProvider.java:147)</div><div id="yui_3_16_0_1_1457385763000_3122" class=""> at org.keycloak.models.UserFederationManager.getUserByUsername(UserFederationManager.java:180)</div><div id="yui_3_16_0_1_1457385763000_3124" class=""> at org.keycloak.models.utils.KeycloakModelUtils.findUserByNameOrEmail(KeycloakModelUtils.java:246)</div><div id="yui_3_16_0_1_1457385763000_3126" class=""> at org.keycloak.authentication.authenticators.directgrant.ValidateUsername.authenticate(ValidateUsername.java:47)</div><div id="yui_3_16_0_1_1457385763000_3128" class=""> at org.keycloak.authentication.DefaultAuthenticationFlow.processFlow(DefaultAuthenticationFlow.java:155)</div><div id="yui_3_16_0_1_1457385763000_3130" class=""> at org.keycloak.authentication.AuthenticationProcessor.authenticateOnly(AuthenticationProcessor.java:776)</div><div id="yui_3_16_0_1_1457385763000_3132" class=""> at org.keycloak.protocol.oidc.endpoints.TokenEndpoint.buildResourceOwnerPasswordCredentialsGrant(TokenEndpoint.java:369)</div><div id="yui_3_16_0_1_1457385763000_3134" class=""> at org.keycloak.protocol.oidc.endpoints.TokenEndpoint.build(TokenEndpoint.java:110)</div><div id="yui_3_16_0_1_1457385763000_3136" class=""> at sun.reflect.GeneratedMethodAccessor279.invoke(Unknown Source)</div><div id="yui_3_16_0_1_1457385763000_3138" class=""> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</div><div id="yui_3_16_0_1_1457385763000_3140" class=""> at java.lang.reflect.Method.invoke(Method.java:497)</div><div id="yui_3_16_0_1_1457385763000_3142" class=""> at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)</div><div id="yui_3_16_0_1_1457385763000_3144" class=""> at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)</div><div id="yui_3_16_0_1_1457385763000_3146" class=""> at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)</div><div id="yui_3_16_0_1_1457385763000_3148" class=""> at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:140)</div><div id="yui_3_16_0_1_1457385763000_3150" class=""> at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:109)</div><div id="yui_3_16_0_1_1457385763000_3152" class=""> at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:135)</div><div id="yui_3_16_0_1_1457385763000_3154" class=""> at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:103)</div><div id="yui_3_16_0_1_1457385763000_3156" class=""> at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)</div><div id="yui_3_16_0_1_1457385763000_3158" class=""> ... 37 more</div><div id="yui_3_16_0_1_1457385763000_3160" class="">Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection</div><div id="yui_3_16_0_1_1457385763000_3162" class=""> at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)</div><div id="yui_3_16_0_1_1457385763000_3164" class=""> at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)</div><div id="yui_3_16_0_1_1457385763000_3166" class=""> at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)</div><div id="yui_3_16_0_1_1457385763000_3168" class=""> at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:235)</div><div id="yui_3_16_0_1_1457385763000_3170" class=""> at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171)</div><div id="yui_3_16_0_1_1457385763000_3172" class=""> at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)</div><div id="yui_3_16_0_1_1457385763000_3174" class=""> at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:162)</div><div id="yui_3_16_0_1_1457385763000_3176" class=""> at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1471)</div><div id="yui_3_16_0_1_1457385763000_3178" class=""> at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:61)</div><div id="yui_3_16_0_1_1457385763000_3180" class=""> ... 65 more</div><div id="yui_3_16_0_1_1457385763000_3182" class="">Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/KeycloakOracleDS</div><div id="yui_3_16_0_1_1457385763000_3184" class=""> at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:146)</div><div id="yui_3_16_0_1_1457385763000_3186" class=""> at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:67)</div><div id="yui_3_16_0_1_1457385763000_3188" class=""> at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)</div><div id="yui_3_16_0_1_1457385763000_3190" class=""> at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380)</div><div id="yui_3_16_0_1_1457385763000_3192" class=""> at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228)</div><div id="yui_3_16_0_1_1457385763000_3194" class=""> ... 70 more</div><div id="yui_3_16_0_1_1457385763000_3196" class="">Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/KeycloakOracleDS</div><div id="yui_3_16_0_1_1457385763000_3198" class=""> at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:646)</div><div id="yui_3_16_0_1_1457385763000_3200" class=""> at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:430)</div><div id="yui_3_16_0_1_1457385763000_3202" class=""> at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:737)</div><div id="yui_3_16_0_1_1457385763000_3204" class=""> at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:138)</div><div id="yui_3_16_0_1_1457385763000_3206" class=""> ... 74 more</div><div id="yui_3_16_0_1_1457385763000_3208" class="">Caused by: javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (30000 [ms])</div><div id="yui_3_16_0_1_1457385763000_3210" class=""> at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:569)</div><div id="yui_3_16_0_1_1457385763000_3212" class=""> at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:627)</div><div id="yui_3_16_0_1_1457385763000_3214" class=""> at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:599)</div><div id="yui_3_16_0_1_1457385763000_3216" class=""> at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:579)</div><div id="yui_3_16_0_1_1457385763000_3218" class=""> ... 77 more</div><div id="yui_3_16_0_1_1457385763000_3220" class=""><br id="yui_3_16_0_1_1457385763000_3222" class=""></div><div id="yui_3_16_0_1_1457385763000_3224" class="">16:10:08,260 ERROR [stderr] (default task-41) javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection</div><div id="yui_3_16_0_1_1457385763000_3226" class="">16:10:08,333 ERROR [stderr] (default task-41) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)</div><div id="yui_3_16_0_1_1457385763000_3228" class="">16:10:08,333 ERROR [stderr] (default task-41) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)</div><div id="yui_3_16_0_1_1457385763000_3230" class=""><br id="yui_3_16_0_1_1457385763000_3232" class=""></div><div id="yui_3_16_0_1_1457385763000_3234" class="">What's the solution to correctly handle a concurrence environment?</div><div id="yui_3_16_0_1_1457385763000_3236" class="">What am doing wrong? Is there a way to make synchronized keycloak jpa transactions?</div><div id="yui_3_16_0_1_1457385763000_3238" class="">Thanks</div><div dir="ltr" id="yui_3_16_0_1_1457385763000_3240" class=""><br id="yui_3_16_0_1_1457385763000_3242" class=""></div></div></body></html>