[keycloak-user] javax.persistence.PessimisticLockException: could not extract ResultSet

Marek Posolda mposolda at redhat.com
Mon Aug 31 10:47:55 EDT 2015


Hi,

how exactly looks "Own code which authenticates the user in DB" ? I 
guess you are accessing USER_ENTITY table somehow with your own 
EntityManager/JDBC code? You should either:
- use just model api and not use Keycloak tables directly from your own 
EntityManager
- switch to different database than default H2

Marek

On 20/08/15 20:47, Bhanu Kiran wrote:
> Hi team,
>
> I am implementing own user federation.
>
>
> As part of this implementing my class is UserFederationProvider.
>
> 1. In method public UserModel getUserByUsername(RealmModel realm, 
> String username) {
>
> //Own code which authenticates the user in DB
>
> Returning  user model
>
> UserModel userModel = session.userStorage().addUser(realm, username);
> userModel.setEnabled(true);
>         userModel.setFederationLink(model.getId());
> return userModel
> }
>
>
> 2. Below exception is generated after UserModel in returned.
>
> Please let me know if i missed anything.
>
> ============================================================================
>
>
> 11:22:01,438 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] 
> (default task-10) SQL Error: 50200, SQLState: HYT00
> 11:22:01,439 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] 
> (default task-10) Timeout trying to lock table "USER_ENTITY"; SQL 
> statement:
> select userentity0_.ID as ID1_47_, userentity0_.CREATED_TIMESTAMP as 
> CREATED_2_47_, userentity0_.EMAIL as EMAIL3_47_, 
> userentity0_.EMAIL_CONSTRAINT as EMAIL_CO4_47_, 
> userentity0_.EMAIL_VERIFIED as EMAIL_VE5_47_, userentity0_.ENABLED as 
> ENABLED6_47_, userentity0_.federation_link as federati7_47_, 
> userentity0_.FIRST_NAME as FIRST_NA8_47_, userentity0_.LAST_NAME as 
> LAST_NAM9_47_, userentity0_.REALM_ID as REALM_I10_47_, 
> userentity0_.SERVICE_ACCOUNT_CLIENT_LINK as SERVICE11_47_, 
> userentity0_.TOTP as TOTP12_47_, userentity0_.USERNAME as 
> USERNAM13_47_ from USER_ENTITY userentity0_ where userentity0_.ID=? 
> and userentity0_.REALM_ID=? [50200-173]
> 11:22:01,442 ERROR 
> [org.keycloak.authentication.AuthenticationProcessor] (default 
> task-10) failed authentication: 
> javax.persistence.PessimisticLockException: could not extract ResultSet
>         at 
> org.hibernate.jpa.spi.AbstractEntityManagerImpl.wrapLockException(AbstractEntityManagerImpl.java:1831)
>         at 
> org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1720)
>         at 
> org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
>         at 
> org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
>         at 
> org.keycloak.models.jpa.JpaUserProvider.getUserById(JpaUserProvider.java:228)
>         at 
> org.keycloak.models.cache.DefaultCacheUserProvider.getUserById(DefaultCacheUserProvider.java:132)
>         at 
> org.keycloak.models.UserFederationManager.deleteInvalidUser(UserFederationManager.java:111)
>         at 
> org.keycloak.models.UserFederationManager.validateAndProxyUser(UserFederationManager.java:134)
>         at 
> org.keycloak.models.UserFederationManager.getUserById(UserFederationManager.java:162)
>         at 
> org.keycloak.models.sessions.mem.ClientSessionAdapter.getAuthenticatedUser(ClientSessionAdapter.java:192)
>         at 
> org.keycloak.authentication.AuthenticationProcessor$Result.getUser(AuthenticationProcessor.java:301)
>         at 
> org.keycloak.authentication.authenticators.browser.AbstractFormAuthenticator.validatePassword(AbstractFormAuthenticator.java:176)
>         at 
> org.keycloak.authentication.authenticators.browser.UsernamePasswordForm.validateForm(UsernamePasswordForm.java:46)
>         at 
> org.keycloak.authentication.authenticators.browser.UsernamePasswordForm.action(UsernamePasswordForm.java:39)
>         at 
> org.keycloak.authentication.DefaultAuthenticationFlow.processAction(DefaultAuthenticationFlow.java:59)
>         at 
> org.keycloak.authentication.DefaultAuthenticationFlow.processAction(DefaultAuthenticationFlow.java:54)
>         at 
> org.keycloak.authentication.AuthenticationProcessor.authenticationAction(AuthenticationProcessor.java:533)
>         at 
> org.keycloak.services.resources.LoginActionsService.processFlow(LoginActionsService.java:306)
>         at 
> org.keycloak.services.resources.LoginActionsService.processAuthentication(LoginActionsService.java:287)
>         at 
> org.keycloak.services.resources.LoginActionsService.authenticateForm(LoginActionsService.java:333)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:497)
>         at 
> org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
>         at 
> org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)
>         at 
> org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)
>         at 
> org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:140)
>         at 
> org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:103)
>         at 
> org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
>         at 
> org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
>         at 
> org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
>         at 
> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
>         at 
> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
>         at 
> io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
>         at 
> io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
>         at 
> org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:59)
>         at 
> io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
>         at 
> io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
>         at 
> io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
>         at 
> io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
>         at 
> io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
>         at 
> org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
>         at 
> io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
>         at 
> io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
>         at 
> io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
>         at 
> io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
>         at 
> io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
>         at 
> io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
>         at 
> io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
>         at 
> io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
>         at 
> io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
>         at 
> io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
>         at 
> io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
>         at 
> org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
>         at 
> io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
>         at 
> io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
>         at 
> io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
>         at 
> io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
>         at 
> io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
>         at 
> io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
>         at 
> io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
>         at 
> io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
>         at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>         at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>         at java.lang.Thread.run(Thread.java:745)
> Caused by: org.hibernate.PessimisticLockException: could not extract 
> ResultSet
>         at org.hibernate.dialect.H2Dialect$2.convert(H2Dialect.java:342)
>         at 
> org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
>         at 
> org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
>         at 
> org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
>         at 
> org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91)
>         at org.hibernate.loader.Loader.getResultSet(Loader.java:2066)
>         at 
> org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863)
>         at 
> org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)
>         at org.hibernate.loader.Loader.doQuery(Loader.java:910)
>         at 
> org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
>         at org.hibernate.loader.Loader.doList(Loader.java:2554)
>         at org.hibernate.loader.Loader.doList(Loader.java:2540)
>         at 
> org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
>         at org.hibernate.loader.Loader.list(Loader.java:2365)
>         at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
>         at 
> org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
>         at 
> org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
>         at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
>         at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
>         at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
>         at 
> org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
>         ... 63 more
> Caused by: org.h2.jdbc.JdbcSQLException: Timeout trying to lock table 
> "USER_ENTITY"; SQL statement:
> select userentity0_.ID as ID1_47_, userentity0_.CREATED_TIMESTAMP as 
> CREATED_2_47_, userentity0_.EMAIL as EMAIL3_47_, 
> userentity0_.EMAIL_CONSTRAINT as EMAIL_CO4_47_, 
> userentity0_.EMAIL_VERIFIED as EMAIL_VE5_47_, userentity0_.ENABLED as 
> ENABLED6_47_, userentity0_.federation_link as federati7_47_, 
> userentity0_.FIRST_NAME as FIRST_NA8_47_, userentity0_.LAST_NAME as 
> LAST_NAM9_47_, userentity0_.REALM_ID as REALM_I10_47_, 
> userentity0_.SERVICE_ACCOUNT_CLIENT_LINK as SERVICE11_47_, 
> userentity0_.TOTP as TOTP12_47_, userentity0_.USERNAME as 
> USERNAM13_47_ from USER_ENTITY userentity0_ where userentity0_.ID=? 
> and userentity0_.REALM_ID=? [50200-173]
>         at 
> org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
>         at org.h2.message.DbException.get(DbException.java:171)
>         at org.h2.message.DbException.get(DbException.java:148)
>         at org.h2.table.RegularTable.doLock(RegularTable.java:521)
>         at org.h2.table.RegularTable.lock(RegularTable.java:455)
>         at org.h2.table.TableFilter.lock(TableFilter.java:145)
>         at org.h2.command.dml.Select.queryWithoutCache(Select.java:611)
>         at org.h2.command.dml.Query.query(Query.java:314)
>         at org.h2.command.dml.Query.query(Query.java:284)
>         at org.h2.command.dml.Query.query(Query.java:36)
>         at org.h2.command.CommandContainer.query(CommandContainer.java:91)
>         at org.h2.command.Command.executeQuery(Command.java:195)
>         at 
> org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:106)
>         at 
> org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
>         at 
> org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
>         ... 79 more
> ==========================================================================================
>
>
>
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20150831/16e3f461/attachment-0001.html 


More information about the keycloak-user mailing list