Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition when initializing ClassAnalyzer with CdiInjecteeSkippingClassAnalyzer #4841

Closed
nhenneaux opened this issue Aug 17, 2021 · 1 comment

Comments

@nhenneaux
Copy link

For now several months, we are getting the following error for some of the builds we execute (I estimate it to 1-5% of all the builds).
It uses Jersey 3.0.2 7, Weld 4.0.2.Final with Java 16.
The error occurs when executing a JUnit test initializing CDI & JAX-RS server, similar to this test https://github.com/nhenneaux/jersey-httpclient-connector/blob/master/src/test/java/com/github/nhenneaux/jersey/connector/httpclient/JettyServerTest.java#L222

Could not find an implementation of ClassAnalyzer with name CdiInjecteeSkippingClassAnalyzer
	at org.jvnet.hk2.internal.ServiceLocatorImpl.getAnalyzer(ServiceLocatorImpl.java:2468)
	at org.jvnet.hk2.internal.Utilities.getClassAnalyzer(Utilities.java:143)
	at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:969)

I suspect a race condition occurs since the class analyzer uses a HashMap and not a thread safe map (java.util.concurrent.ConcurrentMap). Indeed one CPU core cache could see the map full and another the map empty.
https://github.com/javaee/hk2/blob/master/hk2-locator/src/main/java/org/jvnet/hk2/internal/ServiceLocatorImpl.java#L2458

Full stacktrace

java.lang.IllegalStateException: jakarta.servlet.ServletException: org.glassfish.jersey.servlet.ServletContainer-f7acce1==org.glassfish.jersey.servlet.ServletContainer@e976386e{jsp=null,order=-1,inst=true,async=true,src=EMBEDDED:null,STARTED}
...
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: jakarta.servlet.ServletException: org.glassfish.jersey.servlet.ServletContainer-f7acce1==org.glassfish.jersey.servlet.ServletContainer@e976386e{jsp=null,order=-1,inst=true,async=true,src=EMBEDDED:null,STARTED}
	at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:651)
	at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:415)
	at org.eclipse.jetty.servlet.ServletHandler.lambda$initialize$2(ServletHandler.java:690)
	at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
	at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:714)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:392)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:891)
	at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:306)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:171)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:89)
	at org.eclipse.jetty.server.handler.StatisticsHandler.doStart(StatisticsHandler.java:242)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:171)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:121)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:89)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:171)
	at org.eclipse.jetty.server.Server.start(Server.java:469)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:89)
	at org.eclipse.jetty.server.Server.doStart(Server.java:414)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:93)
...	... 9 more
Caused by: A MultiException has 1 exceptions.  They are:
1. java.lang.IllegalStateException: Could not find an implementation of ClassAnalyzer with name CdiInjecteeSkippingClassAnalyzer
	at org.jvnet.hk2.internal.Collector.throwIfErrors(Collector.java:65)
	at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:970)
	at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:1014)
	at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.inject(AbstractHk2InjectionManager.java:207)
	at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.inject(ImmediateHk2InjectionManager.java:30)
	at org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$InjectionManagerInjectedCdiTarget.inject(CdiComponentProvider.java:769)
	at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:161)
	at org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)
	at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
	at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:694)
	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:717)
	at org.jboss.weld.util.ForwardingBeanManager.getReference(ForwardingBeanManager.java:64)
	at org.jboss.weld.bean.builtin.BeanManagerProxy.getReference(BeanManagerProxy.java:87)
	at org.glassfish.jersey.ext.cdi1x.internal.CdiUtil.getBeanReference(CdiUtil.java:129)
	at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanSupplier$1.getInstance(AbstractCdiBeanSupplier.java:72)
	at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanSupplier._provide(AbstractCdiBeanSupplier.java:112)
	at org.glassfish.jersey.ext.cdi1x.internal.GenericCdiBeanSupplier.get(GenericCdiBeanSupplier.java:42)
	at org.glassfish.jersey.inject.hk2.InstanceSupplierFactoryBridge.provide(InstanceSupplierFactoryBridge.java:53)
	at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:129)
	at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:466)
	at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:46)
	at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2103)
	at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:93)
	at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:67)
	at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.lambda$getAllServiceHolders$0(AbstractHk2InjectionManager.java:136)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1242)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
	at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.getAllServiceHolders(AbstractHk2InjectionManager.java:140)
	at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.getAllServiceHolders(ImmediateHk2InjectionManager.java:30)
	at org.glassfish.jersey.internal.inject.Providers.getServiceHolders(Providers.java:307)
	at org.glassfish.jersey.internal.inject.Providers.getCustomProviders(Providers.java:151)
	at org.glassfish.jersey.server.internal.inject.ParamExtractorConfigurator.lambda$init$0(ParamExtractorConfigurator.java:49)
	at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:317)
	at org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorFactory.get(MultivaluedParameterExtractorFactory.java:68)
	at org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider.get(AbstractValueParamProvider.java:67)
	at org.glassfish.jersey.server.internal.inject.PathParamValueParamProvider.createValueProvider(PathParamValueParamProvider.java:71)
	at org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider.getValueProvider(AbstractValueParamProvider.java:93)
	at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParamValueProvider(ParameterValueHelper.java:148)
	at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.createValueProviders(ParameterValueHelper.java:110)
	at org.glassfish.jersey.server.model.ResourceMethodValidator.checkValueProviders(ResourceMethodValidator.java:172)
	at org.glassfish.jersey.server.model.ResourceMethodValidator.checkMethod(ResourceMethodValidator.java:81)
	at org.glassfish.jersey.server.model.ResourceMethodValidator.visitJaxrsResourceMethod(ResourceMethodValidator.java:77)
	at org.glassfish.jersey.server.model.ResourceMethodValidator.visitResourceMethod(ResourceMethodValidator.java:67)
	at org.glassfish.jersey.server.model.ResourceMethod.accept(ResourceMethod.java:876)
	at org.glassfish.jersey.server.model.ComponentModelValidator.validateWithErrors(ComponentModelValidator.java:126)
	at org.glassfish.jersey.server.model.ComponentModelValidator.validateWithErrors(ComponentModelValidator.java:132)
	at org.glassfish.jersey.server.model.ComponentModelValidator.validateWithErrors(ComponentModelValidator.java:132)
	at org.glassfish.jersey.server.model.ComponentModelValidator.validateWithErrors(ComponentModelValidator.java:132)
	at org.glassfish.jersey.server.model.ComponentModelValidator.access$000(ComponentModelValidator.java:55)
	at org.glassfish.jersey.server.model.ComponentModelValidator$1.run(ComponentModelValidator.java:116)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
	at org.glassfish.jersey.server.model.ComponentModelValidator.validate(ComponentModelValidator.java:111)
	at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:366)
	at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:293)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
	at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:232)
	at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:292)
	at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:259)
	at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
	at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154)
	at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:347)
	at jakarta.servlet.GenericServlet.init(GenericServlet.java:178)
	at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:633)
	... 38 more
Caused by: java.lang.IllegalStateException: Could not find an implementation of ClassAnalyzer with name CdiInjecteeSkippingClassAnalyzer
	at org.jvnet.hk2.internal.ServiceLocatorImpl.getAnalyzer(ServiceLocatorImpl.java:2468)
	at org.jvnet.hk2.internal.Utilities.getClassAnalyzer(Utilities.java:143)
	at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:969)
	... 110 more
@nhenneaux
Copy link
Author

Copied to HK2 repository eclipse-ee4j/glassfish-hk2#559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant