cancel
Showing results for 
Search instead for 
Did you mean: 

User transaction timeout not working

juliayoung
Champ in-the-making
Champ in-the-making
I have a user transaction set up similar to this:


        UserTransaction transaction = getTransactionService().getNonPropagatingUserTransaction();
        try {
            transaction.setTransactionTimeout(60);
            transaction.begin();
            long start = System.currentTimeMillis();
            Object responseObj = executeWS(request, response);
            if (responseObj != null) {
                writeResponseObjectToResponse(request, response, responseObj);
            }else {
                response.getWriter().write("");
            }
            long end = System.currentTimeMillis();
            transaction.commit();
            if (LOGGER.isInfoEnabled()) {
                double time = (end - start) / 1000.0;
                LOGGER.info(String.format("Transaction complete after %.2f seconds.", time));
            }
        } catch(Exception e) {
            try {
                transaction.rollback();
            } catch (SystemException se) {
                throw new WebScriptException("Error during rollback.", se);
            }
            throw new WebScriptException("Error executing Web Script " + getDescription() + ".", e);
        }


The transaction does not timeout before the 60 second limit. Is timeout enabled in Alfresco's implementation? Is there something else I could use to timeout and rollback the transaction?

I realize that timing out a running transaction is not an ideal solution but it is what I'v been ordered to do.
9 REPLIES 9

kaynezhang
World-Class Innovator
World-Class Innovator
The UserTransaction object returned bye TransactionService.getNonPropagatingUserTransaction() method is  an instance of org.alfresco.service.transaction.SpringAwareUserTransaction

It seems although SpringAwareUserTransaction implemented the required method setTransactionTimeout,it dose not at all use the time out settings and dose not at all handle time out.

mrogers
Star Contributor
Star Contributor
Although the transaction resources may start timing out after 60 seconds I don't think the API contract for this method is to throw an exception at exactly 60 seconds.    Your thread will be in the middle of doing stuff, probably either waiting on a database call or for IO.

And you really don't want to use that sort of code with alfresco (You should be using the RetryingTransactionHelper)  

I suggest you may need to concentrate upon understand how to time out your "executeWS" method, for example if its a remote web services call you may be able to set a timeout on the IO.

swatnew1
Champ on-the-rise
Champ on-the-rise
Hi Mrogers,

I am trying to set aspect values with transcaction code as below .
Is it ok to use explicit transactional code while setting node properties ?
On bulk upload a rule calls below java method .
But the values are not set for all nodes.
On repetitive execution of rule , all nodes values get set .
That's why I had to use below code .

——————————————————————————————
private void updateInteractionStatus(NodeRef node ,String msg , String interactionId)
   {
   
      UserTransaction transaction = this.getServiceRegistry().getTransactionService().getNonPropagatingUserTransaction();
      try
      {
         transaction.setTransactionTimeout(60);

         transaction.begin();


         //delay( 500);
         //   this.delay();
         log.debug("updateInteractionStatus : :" );
         if(!nodeService.hasAspect(node,  ExtContentModel.ASPECT_INTERACTION_INFO))
         {
            log.debug("updateInteractionStatus :   adding aspect  :" );
            Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>();
            aspectProps.put(ExtContentModel.PROP_INTERACTION_STATUS, msg);
            aspectProps.put(ExtContentModel.PROP_INTERACTIONID, interactionId);
            aspectProps.put(ExtContentModel.PROP_INTERACTION_TYPE, CREATE_INTERACTION_TYPE);

            nodeService.addAspect(node, ExtContentModel.ASPECT_INTERACTION_INFO, aspectProps);
         }
         else
         {
            log.debug("updateInteractionStatus : setting aspect   :" );
            nodeService.removeAspect(node, ExtContentModel.ASPECT_INTERACTION_INFO);
            //   serviceRegistry.getAuthenticationService().authenticate("admin","admin".toCharArray());
            Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>();
            aspectProps.put(ExtContentModel.PROP_INTERACTION_STATUS, msg);
            aspectProps.put(ExtContentModel.PROP_INTERACTIONID, interactionId);
            aspectProps.put(ExtContentModel.PROP_INTERACTION_TYPE, CREATE_INTERACTION_TYPE);

            nodeService.addAspect(node, ExtContentModel.ASPECT_INTERACTION_INFO, aspectProps);
            System.out.println("After setting :"+nodeService.getProperty( node,ExtContentModel.PROP_INTERACTIONID).toString());
         }
         transaction.commit();
      } catch (SystemException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (NotSupportedException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (SecurityException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (IllegalStateException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (RollbackException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (HeuristicMixedException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (HeuristicRollbackException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }
———————————————————————————————–



mrogers
Star Contributor
Star Contributor
No.   As I said above you should use the RetryingTransactionHelper.  

In particular you have
a) forgotten to retry your transactions
b) forgotten to rollback.  You need a finally clause. 

swatnew1
Champ on-the-rise
Champ on-the-rise
I am getting below exception on document movement code on clustered env. and it works on single node.

Document movement code is excecuted in javascript backed webscript .

   private void movedoc(NodeRef targetNode,NodeRef searchedNodeRef) {
   
      super.getNodeService().moveNode(targetNode, searchedNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, super.getNodeService().getProperty(targetNode, ContentModel.PROP_NAME).toString()));

   }


Webscript gets callled for 40 times and then it throws below exception.

2015-01-05 16:46:01,512  ERROR [extensions.webscripts.AbstractRuntime] [http-8080-1] Exception from executeScript - redirecting to status template error: 00050040 Wrapped Exception (with status template): 00050073 Failed to execute script 'classpath*:alfresco/templates/webscripts/base/dms/alfresco/datacorrection/DocumentMove.get.js': setFixedAcls: unexpected shared acl: AclEntity[ ID=365, version=9, aclId=c8936e87-747a-4af1-98ed-c06999b24b6b, isLatest=true, aclVersion=1, inherits=true, inheritsFrom=364, type=2, inheritedAcl=365, isVersioned=false, requiresVersion=false, aclChangeSet=141]
org.springframework.extensions.webscripts.WebScriptException: 00050040 Wrapped Exception (with status template): 00050073 Failed to execute script 'classpath*:alfresco/templates/webscripts/base/dms/alfresco/datacorrection/DocumentMove.get.js': setFixedAcls: unexpected shared acl: AclEntity[ ID=365, version=9, aclId=c8936e87-747a-4af1-98ed-c06999b24b6b, isLatest=true, aclVersion=1, inherits=true, inheritsFrom=364, type=2, inheritedAcl=365, isVersioned=false, requiresVersion=false, aclChangeSet=141]
        at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1067)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
        at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:421)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:447)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:483)
        at org.alfresco.repo.web.scripts.RepositoryContainer$3.doWork(RepositoryContainer.java:529)
        at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:529)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:533)
        at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:333)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
        at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:198)
        at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:176)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.alfresco.scripts.ScriptException: 00050073 Failed to execute script 'classpath*:alfresco/templates/webscripts/base/dms/alfresco/datacorrection/DocumentMove.get.js': setFixedAcls: unexpected shared acl: AclEntity[ ID=365, version=9, aclId=c8936e87-747a-4af1-98ed-c06999b24b6b, isLatest=true, aclVersion=1, inherits=true, inheritsFrom=364, type=2, inheritedAcl=365, isVersioned=false, requiresVersion=false, aclChangeSet=141]
        at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:202)
        at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:212)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:174)
        at org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:102)
        at org.springframework.extensions.webscripts.AbstractWebScript.executeScript(AbstractWebScript.java:1305)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)
        … 30 more
Caused by: org.springframework.dao.ConcurrencyFailureException: setFixedAcls: unexpected shared acl: AclEntity[ ID=365, version=9, aclId=c8936e87-747a-4af1-98ed-c06999b24b6b, isLatest=true, aclVersion=1, inherits=true, inheritsFrom=364, type=2, inheritedAcl=365, isVersioned=false, requiresVersion=false, aclChangeSet=141]
        at org.alfresco.repo.domain.permissions.ADMAccessControlListDAO.setFixedAcls(ADMAccessControlListDAO.java:373)
        at org.alfresco.repo.domain.permissions.ADMAccessControlListDAO.updateInheritance(ADMAccessControlListDAO.java:413)
        at org.alfresco.repo.domain.node.AbstractNodeDAOImpl.moveNode(AbstractNodeDAOImpl.java:1570)
        at org.alfresco.repo.node.db.DbNodeServiceImpl.moveNode(DbNodeServiceImpl.java:2678)
        at sun.reflect.GeneratedMethodAccessor416.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.tenant.MultiTNodeServiceInterceptor.invoke(MultiTNodeServiceInterceptor.java:105)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy19.moveNode(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor416.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxyFactory.java:215)
        at $Proxy32.moveNode(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor416.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.tagging.TagScopePropertyMethodInterceptor.invoke(TagScopePropertyMethodInterceptor.java:152)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:306)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.enterprise.repo.sync.SyncPropertyInterceptor.invoke(SyncPropertyInterceptor.java:258)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:269)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy19.moveNode(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor416.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
        at $Proxy19.moveNode(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor416.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.audit.DisableAuditableBehaviourInterceptor.invoke(DisableAuditableBehaviourInterceptor.java:113)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:161)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.transaction.RetryingTransactionInterceptor$1.execute(RetryingTransactionInterceptor.java:79)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:447)
        at org.alfresco.repo.transaction.RetryingTransactionInterceptor.invoke(RetryingTransactionInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy19.moveNode(Unknown Source)
        at base.dms.alfresco.datacorrection.ArchieveDataCorrectionAction.movedoc(ArchieveDataCorrectionAction.java:169)
        at base.dms.alfresco.datacorrection.ArchieveDataCorrectionAction.moveArchiveDocument(ArchieveDataCorrectionAction.java:156)
        at base.dms.alfresco.datacorrection.DocumentMovementProcessor.doMovement(DocumentMovementProcessor.java:31)
        at sun.reflect.GeneratedMethodAccessor451.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
        at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
        at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
        at org.mozilla.javascript.gen.c1._c1(file:/opt_local/dis/alfresco/apache-tomcat-6.0.35/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/base/dms/alfresco/datacorrection/DocumentMove.get.js:13)
        at org.mozilla.javascript.gen.c1.call(file:/opt_local/dis/alfresco/apache-tomcat-6.0.35/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/base/dms/alfresco/datacorrection/DocumentMove.get.js)
        at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108)
        at org.mozilla.javascript.gen.c1._c0(file:/opt_local/dis/alfresco/apache-tomcat-6.0.35/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/base/dms/alfresco/datacorrection/DocumentMove.get.js:15)
        at org.mozilla.javascript.gen.c1.call(file:/opt_local/dis/alfresco/apache-tomcat-6.0.35/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/base/dms/alfresco/datacorrection/DocumentMove.get.js)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
        at org.mozilla.javascript.gen.c1.call(file:/opt_local/dis/alfresco/apache-tomcat-6.0.35/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/base/dms/alfresco/datacorrection/DocumentMove.get.js)
        at org.mozilla.javascript.gen.c1.exec(file:/opt_local/dis/alfresco/apache-tomcat-6.0.35/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/base/dms/alfresco/datacorrection/DocumentMove.get.js)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:492)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:198)
        … 35 more

mrogers
Star Contributor
Star Contributor
I suggest you start a new thread and give more details such as your version of alfresco.  

And take a look at your transaction boundaries.   You problem is outside of what you have posted here.

swatnew1
Champ on-the-rise
Champ on-the-rise
Hello ,
Alfresco version is 4.1.8 .
Yes, the problem is with transaction only.
Transaction is not getting completed .
Do you want me to post all file of code ?

swatnew1
Champ on-the-rise
Champ on-the-rise
1> I run javabacked  webscript to update node properties and to move document .Node properties are getting updated but node is not moving .
2> I run javascript for rule to move node , only few nodes moving after excecution of rule , not all nodes moving Smiley Sad
3> We have used schedulers to move documents in non-business hour . Its working.
Very strange.
Can you please guide ?


mrogers
Star Contributor
Star Contributor
Please start a new thread rather than hijacking an existing conversation.