Uploaded image for project: 'ActiveMQ Artemis'
  1. ActiveMQ Artemis
  2. ARTEMIS-2566

Thread safety in the Client InitialContext

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.4
    • 2.11.0
    • None
    • None
    • Wildfly 14 on CentOS 7 with a remote Artemis broker

    Description

      When injecting a queue from a federated JNDI-Context we sometimes see exceptions:

      Caused by: javax.naming.NamingException: Something already bound at PostboxSendMailFromTemplateQueue
              at org.apache.activemq.artemis@2.6.3.jbossorg-001//org.apache.activemq.artemis.jndi.ReadOnlyContext.internalBind(ReadOnlyContext.java:158)
              at org.apache.activemq.artemis@2.6.3.jbossorg-001//org.apache.activemq.artemis.jndi.LazyCreateContext.lookup(LazyCreateContext.java:33)
              at org.apache.activemq.artemis@2.6.3.jbossorg-001//org.apache.activemq.artemis.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:270)
              at org.apache.activemq.artemis@2.6.3.jbossorg-001//org.apache.activemq.artemis.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:239)
              at org.apache.activemq.artemis@2.6.3.jbossorg-001//org.apache.activemq.artemis.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:270)
              at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:413)
              at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:413)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:566)
              at org.jboss.as.naming@14.0.1.Final//org.jboss.as.naming.ExternalContextObjectFactory$CachedContext.invoke(ExternalContextObjectFactory.java:145)
              at org.apache.activemq.artemis@2.6.3.jbossorg-001//javax.naming.InitialContext$$$$Proxy1.lookup(Unknown Source)
              at org.jboss.as.naming@14.0.1.Final//org.jboss.as.naming.NamingContext.lookup(NamingContext.java:236)
              at org.jboss.as.naming@14.0.1.Final//org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)
              at org.jboss.as.naming@14.0.1.Final//org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:239)
              at org.jboss.as.naming@14.0.1.Final//org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
              at org.jboss.as.naming@14.0.1.Final//org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
              at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409)
              at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409)
              at org.jboss.as.weld@14.0.1.Final//org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices.resolveResource(WeldResourceInjectionServices.java:237)
              at org.jboss.as.weld@14.0.1.Final//org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices$1.createResource(WeldResourceInjectionServices.java:183)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.injection.AbstractResourceInjection.getResourceReference(AbstractResourceInjection.java:49)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.injection.AbstractResourceInjection.injectResourceReference(AbstractResourceInjection.java:63)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.util.Beans.injectEEFields(Beans.java:309)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:68)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:71)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:117)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:159)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:70)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:700)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:800)
              at org.jboss.weld.core@3.0.5.Final//org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
              ... 38 more
      

      This happens only under heavy load in a simple CDI Bean:

      class NotificationSender {
      
          @Resource(lookup = "java:global/federation/artemis/dynamicQueues/PostboxMailQueue",
                  name = "PostboxMailQueue")
          private Queue queue;
      

      The Javadoc of the initial context is quiet clear that it is not guaranteed to be thread safe:

      An InitialContext instance is not synchronized against concurrent access by multiple threads. Multiple threads each manipulating a different InitialContext instance need not synchronize. Threads that need to access a single InitialContext instance concurrently should synchronize amongst themselves and provide the necessary locking.

      Since synchronization isn't that easy for non-programmatic lookups, it would be cool if the context could handle this at least for simple cases.

      Attachments

        Issue Links

          Activity

            People

              jbertram Justin Bertram
              gtudan Gregor Tudan
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h