0

I am working on the following project and have came across a runtime issue.

http://github.com/dmcquillan314/YouthMinistryHibernate

The instructions to run this project are located in the README.md file although it looks a little messy at the moment. Just view the raw version and it should be readable. Once those steps are completed you should have the environment running.

The issue is on the admin page which is located at:

http://localhost:portno/admin

All accounts are currently being added with a role of admin for testing purposes.

As for steps to recreate the issue see the following:

  1. Signup for a user account it will automatically get the ROLE_ADMIN and ROLE_USER user roles.

  2. Navigate the the /admin url

  3. Add a few groups using the group manager

  4. Attempt to add a text entry and it should freeze up I noticed I didn't see any traffic when i set a breakpoint either which is strange..

  5. If you aren't able to recreate this "freezing" right away then keep trying to create and update different assets it seems to be the page content and events in particular. For now all the controllers are located in the admin controller class until I move them to different controllers.

I've tried several things already to try and fix it such as changing setting around on the session timeout of my db connection pool as well as on hibernate.

I've also tried to set some breakpoints in hopes of seeing where the application freezes however it never seems to get to the breakpoint in the AdminController class that I have set when the error occurs.

The logs are somewhat unhelpful as well here's the last few lines from an instance where it fails:

16:32:19.061 [tomcat-http--13] DEBUG o.s.security.web.FilterChainProxy - /admin/createtextentry reached end of additional filter chain; proceeding with original chain
    16:32:19.061 [tomcat-http--13] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing POST request for [/YouthMinistryHibernate/admin/createtextentry]
    16:32:19.061 [tomcat-http--13] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /admin/createtextentry
    16:32:19.062 [tomcat-http--13] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Returning handler method [public java.lang.String com.youthministry.controller.AdminController.handleCreateTextEntry(com.youthministry.domain.TextEntry,org.springframework.validation.BindingResult,org.springframework.ui.Model)]
    16:32:19.062 [tomcat-http--13] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'adminController'
    16:32:19.063 [tomcat-http--13] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'txManager'
    16:32:19.063 [tomcat-http--13] DEBUG o.s.o.h.HibernateTransactionManager - Creating new transaction with name [com.youthministry.service.impl.GroupServiceImpl.getGroupById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
    16:32:19.063 [tomcat-http--13] DEBUG o.s.o.h.HibernateTransactionManager - Opened new Session [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])] for Hibernate transaction
    16:32:19.063 [tomcat-http--13] DEBUG o.s.o.h.HibernateTransactionManager - Preparing JDBC Connection of Hibernate Session [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])]
    16:32:19.063 [tomcat-http--13] DEBUG o.s.jdbc.datasource.DataSourceUtils - Setting JDBC   Connection [org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler@2dd92714[valid=true]] read-only

So far I have learned that it is not a deadlock via my database but rather a deadlock in spring somewhere around the DataSourceUtils when trying to access the Connection ProxyHandler as shown above in the server logs as the last long entry.

I am using Spring 3.1, Hibernate 4.1 and DBCP as my connection pool.

Any help is greatly appreciated I've been struggling with this issue for a week or so now.

dmcqu314
  • 875
  • 11
  • 29
  • What database are you using? When the application hangs, can you get the number of active transactions on the DB? This smells like a deadlock issue. – acdcjunior May 21 '13 at 03:07
  • I'm using mysql as my database. I'm not sure how to get the number of active transactions. Can this be done in the mysql console or mysql workbench – dmcqu314 May 21 '13 at 04:00
  • I'm no expert in mysql, but try `SHOW ENGINE INNODB STATUS`. See what it means (and much more info) here: http://www.xaprb.com/blog/2006/07/31/how-to-analyze-innodb-mysql-locks/ – acdcjunior May 21 '13 at 04:43
  • I added in the relevant logs for the locks. let me know if there's anything else – dmcqu314 May 21 '13 at 05:05
  • Did you get this while the application was frozen? If not, go there, hang it, then extract that info. Another thing, nearby where you think the problem is, everytime you persist something (like `session.save(textEntry);`), place a `session.flush()` right after (like `session.save(textEntry); session.flush();`). This will make you see the exception (or problem; or hang) as soon as it happens (instead of waiting for hibernate to flush the `session` itself - what would probably take place after a `session.getTransaction().commit()` which can be far far away from what's really causing trouble). – acdcjunior May 21 '13 at 05:23
  • I just finished adding in the flush statements where you had suggested. It still doesn't seem to be throwing the exception where it should. I just checked the mysql status as well and it's the same error message as I had posted above. – dmcqu314 May 22 '13 at 03:54
  • What error? The server hangs? (What do you mean by hanging? No other user is able to use the system or just the "hanger"?) – acdcjunior May 22 '13 at 13:04
  • The server hangs due to what I now believe is a deadlock since the user's current thread will be terminated. However if you clear the state of the browser and relogin then you will be able to view the pages again although once you try to update another object you once again receive the same hanging issue. – dmcqu314 May 22 '13 at 14:19
  • So it probably is a deadlock in the application, then, not in the database. To make sure it is not in the database, when the app hangs, turn off (close or kill network connection to) the database. If the DB has a role in the deadlock, the app will get back on (with an exception, of course, but one near where the problem really is). – acdcjunior May 22 '13 at 14:29
  • Yes, you were right the deadlock is in the application. I went through your steps and it locked on this step: 12:15:44.271 [tomcat-http--10] DEBUG o.s.jdbc.datasource.DataSourceUtils - Setting JDBC Connection [org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler@6d6425ca[valid=true]] read-only – dmcqu314 May 22 '13 at 17:17
  • @acdcjunior What would be my next step to start resolving this issue? – dmcqu314 May 23 '13 at 14:10
  • I don't really understand what you said in (and after) the *"it locked on this step: "* part. Can you describe what you actually did? Also, append it to the question, it is easier to see (there's more room), and also others will be able to help as well. – acdcjunior May 23 '13 at 14:30
  • @acdcjunior I've updated the post above with an explanation of the issue. I've also removed the now irrelevant logs above the mysql locked tables to avoid confusion. – dmcqu314 May 24 '13 at 00:18

1 Answers1

0

The problem turned out to be a database cardinality issues.

For collections I was using OneToMany instead of ManyToMany where ManyToMany should have been used.

As to why it was hanging as a result I am unsure of. But the important part is that it's fixed now.

dmcqu314
  • 875
  • 11
  • 29