I have a grails transactional service that does some (lengthy) processing. During processing, I would like to update the "percentComplete" value (which will ultimately be used to display the progress bar on the interface). This, obviously, should be written immediately (i.e. not as part of the current transaction), otherwise it does not matter.
Therefore, I use the Grails Transaction Processing Plugin and, in particular, the withNewTransaction method to start a new transaction, within which the percentComplete attribute is updated.
My problem is that the second time, using the updatePercentComplete () method, the application freezes when trying to exit the "withNewTransaction" method (presumably when it tries to commit the transaction).
Notes:
- If I comment on session cleanup in the main service method, there is no problem (by the way, this cleanup along with cleanup is required for performance reasons in my real application).
- using the hsql database is no problem (see DataSources.groovy).
- also uses the grails artists plugin, but I don't think this causes any problems on their own (see LibraryServiceTests, which also freezes and bypasses the plugin).
Where should I look for debugging this problem? Maybe there are some log levels that I can install in grails / hibernate somewhere to indicate what is happening?
The thread doing the work seems to be stuck trying to read from the socket, see stack trace below. It seems that the JVM itself did not have any real deadlocks.
Here is my service class, link to the full project below:
package withtransactiontest class LibraryService { static transactional = true def sessionFactory def loadBooks(library) { int repeat = 5 repeat.times { updatePercentComplete(library, it * (100 / repeat))
Link to grails project with integration test that recreates the problem
Stacktrace from stream "worker":
Thread [pool-1-thread-1] (paused)
SocketInputStream.socketRead0 (FileDescriptor, byte [], int, int, int) string: not available [native method]
SocketInputStream.read (byte [], int, int): 129
ReadAheadInputStream.fill (int): 114
ReadAheadInputStream.readFromUnderlyingStreamIfNecessary (byte [], int, int): 161
ReadAheadInputStream.read (byte [], int, int): 189
MysqlIO.readFully (InputStream, byte [], int, int): 2499 MysqlIO.reuseAndReadPacket (Buffer, int): 2952
MysqlIO.reuseAndReadPacket (buffer): 2941
MysqlIO.checkErrorPacket (int): 3489
MysqlIO.sendCommand (int, String, Buffer, boolean, String, int): 1959
MysqlIO.sqlQueryDirect (StatementImpl, String, String, Buffer, int, int, int, boolean, String, Field []): 2113
JDBC4Connection (ConnectionImpl) .execSQL (StatementImpl, String, int, Buffer, int, int, boolean, String, Field [], boolean): 2568 JDBC4PreparedStatement (PreparedStatement) .executeInternal (int, Buffer, boolean, boolean, Field [], boolean): 2113
JDBC4PreparedStatement (PreparedStatement) .executeUpdate (byte [] [], InputStream [], boolean [], int [], boolean [], boolean): 2409
JDBC4PreparedStatement (PreparedStatement) .executeUpdate (logical, logical) string: 2327
JDBC4PreparedStatement (PreparedStatement) .executeUpdate (): 2312
DelegatingPreparedStatement.executeUpdate (): 105
DelegatingPreparedStatement.executeUpdate (): 105
GroovyAwareSingleTableEntityPersister (AbstractEntityPersister) .update (Serializable, Object [], Object [], Object, boolean [], int, Object, Object, String, SessionImplementor): 2435
GroovyAwareSingleTableEntityPersister (AbstractEntityPersister) .updateOrInsert (Serializable, Object [], Object [], Object, boolean [], int, Object, Object, String, SessionImplementor): 2335
GroovyAwareSingleTableEntityPersister (AbstractEntityPersister) .update (Serializable, Object [], int [], boolean, Object [], Object, Object, Object, SessionImplementor): 2635
EntityUpdateAction.execute (): 115
Line ActionQueue.execute (Executable): 279
Line ActionQueue.executeActions (List): 263
String ActionQueue.executeActions (): 168
PatchedDefaultFlushEventListener.performExecutions (EventSource) String: 46
PatchedDefaultFlushEventListener (DefaultFlushEventListener). String .onFlush (FlushEvent): 50
SessionImpl.flush (): 1027
SessionImpl.managedFlush () String: 365
JDBCTransaction.commit (): 137
GrailsHibernateTransactionManager (HibernateTransactionManager) .doCommit (DefaultTransactionStatus): 656 GrailsHibernateTransactionManager (AbstractPlatformTransactionManager) .processCommit (DefaultTransactionStatus): 754 GrailsHibernateTransactionManager (Abstract) TransformerManager
String TransactionTemplate.execute (TransactionCallback): 147
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
PojoMetaMethodSite $ PojoCachedMethodSite.invoke (Object, Object []) string: 188
PojoMetaMethodSite $ PojoCachedMethodSite (PojoMetaMethodSite) .call (Object, Object []) string: 52 PojoMetaMethodSite $ PojoCachedMethodSite (AbstractCallSite) .call (object, object): 124
GroovyDynamicMethods $ _doWith_closure1.doCall (card, card, close): 55
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
PogoMetaMethodSite $ PogoCachedMethodSiteNoUnwrapNoCoerce.invoke (Object, Object []) string: 266
PogoMetaMethodSite $ PogoCachedMethodSiteNoUnwrapNoCoerce (PogoMetaMethodSite) .callCurrent (GroovyObject, Object []) line: 51
PogoMetaMethodSite $ PogoCachedMethodSiteNoUnwrapNoCoerce (AbstractCallSite) .callCurrent (GroovyObject, Object, Object, Object): 157
GroovyDynamicMethods $ _doWith_closure1.call (map, map, close): not available
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
PogoMetaMethodSite $ PogoCachedMethodSiteNoUnwrapNoCoerce.invoke (Object, Object []) string: 266
PogoMetaMethodSite $ PogoCachedMethodSiteNoUnwrapNoCoerce (PogoMetaMethodSite) .call (object, object []) string: 63 PogoMetaMethodSite $ PogoCachedMethodSiteNoUnwrapNoCoerce (object, .allCall
GroovyDynamicMethods line $ _doWith_closure3.doCall (map, closure): 65 NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
PogoMetaMethodSite $ PogoCachedMethodSite.invoke (object, object []) string: 225
PogoMetaMethodSite $ PogoCachedMethodSite (PogoMetaMethodSite) .callCurrent (GroovyObject, Object []) line: 51
PogoMetaMethodSite $ PogoCachedMethodSite (AbstractCallSite) .callCurrent (GroovyObject, Object, Object): 153
GroovyDynamicMethods $ _doWith_closure3.doCall (Close): Not Available
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
CachedMethod.invoke (object, object []): 90
CachedMethod (MetaMethod) .doMethodInvoke (Object, Object []) string: 233 ExpandoMetaClass (MetaClassImpl) .invokeMethod (class, object, string, object [], logical, logical string): 1058
ExpandoMetaClass.invokeMethod (class, object, string, object [], logical, logical string): 1070 ExpandoMetaClass (MetaClassImpl) .invokeMethod (Object, String, Object []) string: 886
GroovyDynamicMethods $ _doWith_closure3 (Closing) .call (Object []) line: 282 ClosureStaticMetaMethod.invoke (Object, Object []) line: 59
StaticMetaMethodSite $ StaticMetaMethodSiteNoUnwrapNoCoerce.invoke (object, object []) string: 148
StaticMetaMethodSite $ StaticMetaMethodSiteNoUnwrapNoCoerce (StaticMetaMethodSite) .call (Object, Object []) line: 88 StaticMetaMethodSite $ StaticMetaMethodSiteNoUnwrapNoCoerce (AbstractCallSite).
LibraryService.updatePercentComplete line (object, object): 34
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
CachedMethod.invoke (object, object []): 90
CachedMethod (MetaMethod) .doMethodInvoke (Object, Object []) string: 233 ExpandoMetaClass (MetaClassImpl) .invokeMethod (class, object, string, object [], logical, logical string): 1058
ExpandoMetaClass.invokeMethod (class, object, string, object [], logical, logical string): 1070 ExpandoMetaClass (MetaClassImpl) .invokeMethod (Object, String, Object []) string: 886
ExpandoMetaClass (MetaClassImpl) .invokeMethod (class, object, string, object [], logical, logical string): 1003
ExpandoMetaClass.invokeMethod (class, object, string, object [], logical, logical string): 1070 ExpandoMetaClass (MetaClassImpl) .invokeMethod (Object, String, Object []) string: 886
PogoMetaClassSite.callCurrent (GroovyObject, Object []): 66
PogoMetaClassSite (AbstractCallSite) .callCurrent (GroovyObject, Object, Object): 153 LibraryService $ _loadBooks_closure1.doCall (Object): 13
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
CachedMethod.invoke (object, object []): 90
CachedMethod (MetaMethod) .doMethodInvoke (Object, Object []) string: 233 ExpandoMetaClass (MetaClassImpl) .invokeMethod (class, object, string, object [], logical, logical string): 1058
ExpandoMetaClass.invokeMethod (class, object, string, object [], logical, logical string: 1070 ExpandoMetaClass (MetaClassImpl) .invokeMethod (Object, String, Object []) string: 886
LibraryService $ _loadBooks_closure1 (Closing) .call (Object []) line: 282
LibraryService $ _loadBooks_closure1 (Closing) .call (Object) line: 295
String DefaultGroovyMethods.times (Number, Closure): 9487
dgm $ 630.invoke (Object, Object []) string: not available
PojoMetaMethodSite $ PojoMetaMethodSiteNoUnwrapNoCoerce.invoke (Object, Object []) string: 270
PojoMetaMethodSite $ PojoMetaMethodSiteNoUnwrapNoCoerce (PojoMetaMethodSite) .call (Object, Object []) line: 52
PojoMetaMethodSite $ PojoMetaMethodSiteNoUnwrapNoCoerce (AbstractCallSite) .call (object, object): 124
LibraryService.loadBooks (Object): 12
LibraryService $$ FastClassByCGLIB $$ f97d911e.invoke (int, Object, Object []) string: not available
MethodProxy.invoke (object, object []) string: 149
Cglib2AopProxy $ CglibMethodInvocation.invokeJoinpoint (): 688
Cglib2AopProxy $ CglibMethodInvocation (ReflectiveMethodInvocation) .proceed (): 150
TransactionInterceptor.invoke (MethodInvocation) String: 110
Cglib2AopProxy $ CglibMethodInvocation (ReflectiveMethodInvocation) .proceed (): 172
Cglib2AopProxy $ DynamicAdvisedInterceptor.intercept (object, method, object [], Proxy method): 621 LibraryService $$ EnhancerByCGLIB $$ c098c6ba.loadBooks (Object) string: not available LibraryService $ loadBooks.call (object, object): not available
LibraryController $ _closure4_closure9.doCall (Object): 30
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
PogoMetaMethodSite $ PogoCachedMethodSite.invoke (object, object []) string: 225
PogoMetaMethodSite $ PogoCachedMethodSite (PogoMetaMethodSite) .callCurrent (GroovyObject, Object []) line: 51
PogoMetaMethodSite $ PogoCachedMethodSite (AbstractCallSite) .callCurrent (GroovyObject, Object): 149
LibraryController $ _closure4_closure9.doCall () string: not available
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
CachedMethod.invoke (object, object []): 90
CachedMethod (MetaMethod) .doMethodInvoke (Object, Object []) string: 233 ExpandoMetaClass (MetaClassImpl) .invokeMethod (class, object, string, object [], logical, logical string): 1058
ExpandoMetaClass.invokeMethod (class, object, string, object [], logical, logical string): 1070 ExpandoMetaClass (MetaClassImpl) .invokeMethod (Object, String, Object []) string: 886
LibraryController $ _closure4_closure9 (Closing) .call (Object []) line: 282
ConvertedClosure.invokeCustom (object, method, object []) line: 51
ConvertingClosure (ConversionHandler) .invoke (object, method, object []) string: 82
$ Proxy6.call (): not available
string java_util_concurrent_Callable $ call.call (Object): not available PersistenceContextCallableWrapper $ _call_closure1.doCall (object): 36
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
PogoMetaMethodSite $ PogoCachedMethodSite.invoke (object, object []) string: 225
PogoMetaMethodSite $ PogoCachedMethodSite (PogoMetaMethodSite) .callCurrent (GroovyObject, Object []) line: 51
PogoMetaMethodSite $ PogoCachedMethodSite (AbstractCallSite) .callCurrent (GroovyObject, Object): 149
PersistenceContextCallableWrapper $ _call_closure1.doCall (): not available
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
CachedMethod.invoke (Object, Object []): 90
CachedMethod (MetaMethod) .doMethodInvoke (Object, Object []) string: 233 ExpandoMetaClass (MetaClassImpl) .invokeMethod (class, object, string, object [], logical, logical string): 1058
ExpandoMetaClass.invokeMethod (class, object, string, object [], logical, logical string): 1070 ExpandoMetaClass (MetaClassImpl) .invokeMethod (Object, String, Object []) string: 886
PersistenceContextCallableWrapper $ _call_closure1 (Closing) .call (Object []) line: 282
PersistenceContextCallableWrapper $ _call_closure1 (Closing) .call (): 277
Closing the line $ call.call (Object): not available
PersistenceContextCallableWrapper (PersistenceContextWrapper) .wrap (Closure): 35
NativeMethodAccessorImpl.invoke0 (method, object, object []) string: not available [native method]
NativeMethodAccessorImpl.invoke (object, object []) string: 39
DelegatingMethodAccessorImpl.invoke (object, object []) string: 25
Method.invoke (Object, Object ...): 597
PogoMetaMethodSite $ PogoCachedMethodSiteNoUnwrapNoCoerce.invoke (Object, Object []) string: 266
PogoMetaMethodSite $ PogoCachedMethodSiteNoUnwrapNoCoerce (PogoMetaMethodSite) .callCurrent (GroovyObject, Object []) line: 51
PogoMetaMethodSite $ PogoCachedMethodSiteNoUnwrapNoCoerce (AbstractCallSite) .callCurrent (GroovyObject, Object): 149
PersistenceContextCallableWrapper.call (): 36
FutureTask $ Sync.innerRun (): 303
String FutureTask.run (): 138
ThreadPoolExecutor $ Worker.runTask (Runnable): 886
ThreadPoolExecutor $ Worker.run (): 908
Thread.run () line: 680