12 Replies Latest reply on Jul 21, 2005 10:45 AM by jameselliot

    Hibernate/TreeCache/JBoss error

    jameselliot

      Hi,

      I am currently trying to set up a replicated cache accross two jboss servers. The cache is being used for hibernate.

      I am getting an exception thrown from JGroups (which I believe should not be thrown). The exception is:

      org.hibernate.cache.CacheException: ChannelException: java.lang.Exception: exception caused by UDP.start(): java.lang.Exception: UDP.createSockets(): cannot list on any port in range 0-1
       at org.hibernate.cache.TreeCacheProvider.start(TreeCacheProvider.java:58)
       at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:167)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055)
       at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:568)
       at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:503)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1075)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:349)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:257)
       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:222)
       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:146)
       at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285)
       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:317)
       at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:131)
       at org.springframework.web.struts.ContextLoaderPlugIn.createWebApplicationContext(ContextLoaderPlugIn.java:352)
       at org.springframework.web.struts.ContextLoaderPlugIn.initWebApplicationContext(ContextLoaderPlugIn.java:295)
       at org.springframework.web.struts.ContextLoaderPlugIn.init(ContextLoaderPlugIn.java:224)
       at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:839)
       at org.apache.struts.action.ActionServlet.init(ActionServlet.java:332)
       at javax.servlet.GenericServlet.init(GenericServlet.java:211)
       at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
       at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:925)
       at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3857)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4118)
       at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
       at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
       at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.apache.commons.modeler.BaseModelMBean.invoke(BaseModelMBean.java:503)
       at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:150)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.apache.catalina.core.StandardContext.init(StandardContext.java:5005)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.apache.commons.modeler.BaseModelMBean.invoke(BaseModelMBean.java:503)
       at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:150)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.web.tomcat.tc5.TomcatDeployer.performDeployInternal(TomcatDeployer.java:274)
       at org.jboss.web.tomcat.tc5.TomcatDeployer.performDeploy(TomcatDeployer.java:91)
       at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:357)
       at org.jboss.web.WebModule.startModule(WebModule.java:68)
       at org.jboss.web.WebModule.startService(WebModule.java:46)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:272)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:222)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:897)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:418)
       at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
       at $Proxy28.start(Unknown Source)
       at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:394)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:964)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:775)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:738)
       at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:121)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
       at $Proxy8.deploy(Unknown Source)
       at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:325)
       at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:483)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:204)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:215)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:194)
      Caused by: ChannelException: java.lang.Exception: exception caused by UDP.start(): java.lang.Exception: UDP.createSockets(): cannot list on any port in range 0-1
       at org.jgroups.JChannel.connect(JChannel.java:328)
       at org.jboss.cache.TreeCache.startService(TreeCache.java:1112)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:272)
       at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:173)
       at org.hibernate.cache.TreeCacheProvider.start(TreeCacheProvider.java:55)
       ... 91 more
      


      This comes from the following line of code in UDP.java in the private DatagramSocket createDatagramSocketWithBindPort() throws Exception method.

      // Cannot listen at all, throw an Exception
       if(rcv_port >= max_port + 1) { // +1 due to the increment above
       throw new Exception("UDP.createSockets(): cannot list on any port in range " +
       bind_port + '-' + (bind_port + port_range));
       }
      


      However this should not be called if the bind address is 0 (as implied by the stack trace)

       if(bind_port > 0) {
       sock=createDatagramSocketWithBindPort();
       }
      


      Both servers are running JBoss 4.0.2, both have the same war file deployed. One deployment results in the above error, whereas the other deployment occurs okay. Both servers are running identical operating systems.


      The configuration from treecache.xml is:
       <server>
       <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/>
      
       <mbean code="org.jboss.invocation.jrmp.server.JRMPProxyFactory" name="localhost:service=proxyFactory,type=jrmp,target=factory">
       <attribute name="InvokerName">jboss:service=invoker,type=jrmp</attribute>
       <attribute name="TargetName">jboss.cache:service=TreeCache</attribute>
       <attribute name="JndiName">VicopCache</attribute>
       <attribute name="InvokeTargetMethod">true</attribute>
       <attribute name="ExportedInterface">org.jboss.cache.TreeCacheMBean</attribute>
       <attribute name="ClientInterceptors">
       <iterceptors>
       <interceptor>org.jboss.proxy.ClientMethodInterceptor</interceptor>
       <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
       <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>
       </iterceptors>
       </attribute>
       <depends>jboss:service=invoker,type=jrmp</depends>
       <depends>jboss.cache:service=TreeCache</depends>
       <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
       <attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute>
       <attribute name="ClusterName">VicopTestCluster</attribute>
       <attribute name="CacheMode">REPL_ASYNC</attribute>
       <attribute name="ClusterConfig">
       <config>
       <!-- UDP: if you have a multihomed machine,
       set the bind_addr attribute to the appropriate NIC IP address -->
       <!-- UDP: On Windows machines, because of the media sense feature
       being broken with multicast (even after disabling media sense)
       set the loopback attribute to true -->
       <UDP mcast_addr="225.10.10.20" mcast_port="45566"
       ip_ttl="64" ip_mcast="true"
       mcast_send_buf_size="150000" mcast_recv_buf_size="80000"
       ucast_send_buf_size="150000" ucast_recv_buf_size="80000"
       loopback="false"/>
       <PING timeout="2000" num_initial_members="3"
       up_thread="false" down_thread="false"/>
       <MERGE2 min_interval="10000" max_interval="20000"/>
       <FD shun="true" up_thread="true" down_thread="true"/>
       <VERIFY_SUSPECT timeout="1500"
       up_thread="false" down_thread="false"/>
       <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
       max_xmit_size="8192" up_thread="false" down_thread="false"/>
       <UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"
       down_thread="false"/>
       <pbcast.STABLE desired_avg_gossip="20000"
       up_thread="false" down_thread="false"/>
       <FRAG frag_size="8192"
       down_thread="false" up_thread="false"/>
       <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
       shun="true" print_local_addr="true"/>
       <pbcast.STATE_TRANSFER up_thread="false" down_thread="false"/>
       </config>
       </attribute>
       </mbean>
      </server>
      


      The hibernate configuration (from springframework) is:

      <property name="hibernateProperties">
       <props>
       <prop key="hibernate.dialect">org.hibernate.dialect.FirebirdDialect</prop>
       <prop key="hibernate.show_sql">true</prop>
       <prop key="hibernate.cache.provider_class">org.hibernate.cache.TreeCacheProvider</prop>
       <prop key="hibernate.treecache.mbean.object_name">VicopCache</prop>
       <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
       <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
       </props>
       </property>
      


      Port 45566 has been opened on shorewall for both servers.

      Addtionally the MANIFEST.INF from jgroups.jar is:

      Main-Class: org.jgroups.demos.Draw
      Implementation-Title: JBoss [Zion]
      Specification-Vendor: JBoss (http://www.jboss.org/)
      Specification-Version: 4.0.2
      Implementation-Vendor-Id: http://www.jboss.org/
      Implementation-Version: 4.0.2 (build: CVSTag=JBoss_4_0_2 date=20050502
       2023)
      Implementation-Vendor: JBoss Inc.
      Implementation-URL: http://www.jboss.org/
      


      And this is the same on both servers.


      I am very confused, any help would be greatly appreciated.

      Kind regards,

      James.


        • 1. Re: Hibernate/TreeCache/JBoss error
          belaban

          This code should indeed only be called if UDP.bind_port > 0 !

          Are you running
          - IBM's JDK ?
          - IPv6 ?

          • 2. Re: Hibernate/TreeCache/JBoss error
            jameselliot

            Bela,

            IPv6 is enabled, but it is not being used.

            Using standard Linux JVM from Sun. (JDK 1.5.0).

            -James.

            • 3. Re: Hibernate/TreeCache/JBoss error
              belaban
              • 4. Re: Hibernate/TreeCache/JBoss error
                jameselliot

                I tried adding preferred IPv4 support as given for the test, this gave the same error:

                james@chef:~$ java -Djava.net.preferIPv4Stack=true org.jgroups.demos.Draw
                
                log4j:WARN No appenders could be found for logger (org.jgroups.conf.ClassConfigurator).
                log4j:WARN Please initialize the log4j system properly.
                ChannelException: java.lang.Exception: exception caused by UDP.start(): java.lang.Exception: UDP.createSockets(): cannot list on any port in range 0-1
                 at org.jgroups.JChannel.connect(JChannel.java:328)
                 at org.jgroups.demos.Draw.go(Draw.java:147)
                 at org.jgroups.demos.Draw.main(Draw.java:117)
                


                With out the preferred IPv4 support I get the same error:

                james@chef:~$ java org.jgroups.demos.Draw
                
                log4j:WARN No appenders could be found for logger (org.jgroups.conf.ClassConfigurator).
                log4j:WARN Please initialize the log4j system properly.
                ChannelException: java.lang.Exception: exception caused by UDP.start(): java.lang.Exception: UDP.createSockets(): cannot list on any port in range 0-1
                 at org.jgroups.JChannel.connect(JChannel.java:328)
                 at org.jgroups.demos.Draw.go(Draw.java:147)
                 at org.jgroups.demos.Draw.main(Draw.java:117)
                


                • 5. Re: Hibernate/TreeCache/JBoss error
                  belaban

                  Okay, the problem is that 4.0.2 uses JGroups 2.2.7. In 2.2.7, the check for a bind_port > 0 is *not* done.
                  A port of 0 means an ephemeral port, but some JDK/OSs don't implement this correctly.

                  What can you do ?
                  - Set bind_port to a valid value
                  - Upgrade to 2.2.8
                  The upgrade should be simple, because the API hasn't changed between 2.2.7 and 2.2.8. You *may* have to remove some parameters in your XML file, although I don't think that is the case.

                  • 6. Re: Hibernate/TreeCache/JBoss error
                    belaban

                    You can find out the JGroups version by
                    java -cp jgroups.jar org.jgroups.Version

                    • 7. Re: Hibernate/TreeCache/JBoss error
                      jameselliot

                      Upgraded to latest version and the cache now starts up.

                      Thanks,

                      James.

                      • 8. Re: Hibernate/TreeCache/JBoss error
                        binario

                        Hi James,

                        I'm currently trying to setup a replicated clustered cache across two jboss nodes aswell. I'm trying to use it for the second level cache in Hibernate. I'm getting a fair few problems as my post on this forum today shows. Can you tell me, have you been successful with this? If you could share your config files with us if you have been successful that would be fantastic.

                        thanks,
                        Binario

                        • 9. Re: Hibernate/TreeCache/JBoss error
                          jameselliot

                          Binario,

                          please see my latest post for config file, this however does not yet work.

                          -James.

                          • 10. Re: Hibernate/TreeCache/JBoss error
                            binario

                            Thanks James,

                            if you could also post up the relevant section of your JBossService.xml file - ie, the transaction section, and if you could tell us if you get it working that would be great.

                            Ps - is it for the hibernate second level cache?
                            If so - watch out for having to turn on the querycache. We ran into that as an issue today.

                            • 11. Re: Hibernate/TreeCache/JBoss error
                              jameselliot

                              Binario,

                              I configure the hibernate setup in the springframework. The hibernate properties set are:

                              <property name="hibernateProperties">
                               <props>
                               <prop key="hibernate.dialect">org.hibernate.dialect.FirebirdDialect</prop>
                               <prop key="hibernate.show_sql">true</prop>
                               <prop key="hibernate.cache.provider_class">org.hibernate.cache.TreeCacheProvider</prop>
                               <prop key="hibernate.treecache.mbean.object_name">VicopCache</prop>
                               <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
                               <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
                               </props>
                               </property>
                              


                              Hope this helps,

                              James.

                              • 12. Re: Hibernate/TreeCache/JBoss error
                                jameselliot

                                Binario,

                                Have you set a java:comp/UserTransaction Property? Is this what you have then been configuring as an mbean?

                                -James.