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

<java.lang.IllegalStateException> at runtime on using two methods with same cache name but different key #17284

Closed
sg11pankaj opened this issue Aug 1, 2020 · 2 comments · Fixed by #17286
Assignees
Labels
Milestone

Comments

@sg11pankaj
Copy link

sg11pankaj commented Aug 1, 2020

Describe the bug
We've two services,marked as cacheable with same name but different key as below. When both these are called one by one, Hazelcast throw <java.lang.IllegalStateException> Cannot overwrite a Cache's CacheManager. Tried many options but it is still now working. We are using Hazelcast version 4.0 and spring-context 5.2.7.

    @Transactional(readOnly = true)
    @Cacheable(value = "find", key = "#root.methodName", unless = "#result == null or #result.size() == 0")
    public List<GenericItem> getProviderTaxIDs() {
        return providerRepository.getProviderTaxIDs();
    }

    @Transactional(readOnly = true)
    @Cacheable(value = "find", key = "#root.methodName", unless = "#result == null or #result.size() == 0")
    public List<String> getEnrollmentLOBList() {
        return imlrAnalysisDAO.getEnrollmentLobList();
    }
exception.MessageException: <xxxx.xxxx.xxx.exception.HandlerException> Cannot overwrite a Cache's CacheManager.
	from command mlr.getProviderTaxIDs (? -> ppa-service)
	at xxxx.xxxx.xxx.conf.service.ExceptionConverter.handleAndThrow(ExceptionConverter.java:103) ~[?:?]
	at xxxx.xxxx.xxx.handler.MLRhandler.getProviderTaxIDs(MLRhandler.java:70) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_144]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_144]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_144]
	at xxxx.xxxx.xxx.isc.core.command.MethodCommandRef.executeCommand(MethodCommandRef.scala:188) ~[isc-core-2.0.15.jar:?]
	at xxxx.xxxx.xxx.isc.core.command.MethodCommandRef.receiveCommand(MethodCommandRef.scala:127) ~[isc-core-2.0.15.jar:?]
	at xxxx.xxxx.xxx.api.LocalServiceRef$$anonfun$receiveCommand$2.apply(LocalServiceRef.scala:50) ~[service-api-2.0.13.jar:?]
	at com.edifecs.servicemanager.api.LocalServiceRef$$anonfun$receiveCommand$2.apply(LocalServiceRef.scala:49) ~[service-api-2.0.13.jar:?]
	at scala.Option.map(Option.scala:146) ~[scala-library-2.11.7.jar:?]
	at com.edifecs.servicemanager.api.LocalServiceRef.receiveCommand(LocalServiceRef.scala:49) ~[service-api-2.0.13.jar:?]
	at com.edifecs.epp.isc.core.command.CommandReceiverActor$$anonfun$handleCommand$2$$anonfun$apply$4.apply(CommandReceiverActor.scala:104) ~[isc-core-2.0.15.jar:?]
	at com.edifecs.epp.isc.core.command.CommandReceiverActor$$anonfun$handleCommand$2$$anonfun$apply$4.apply(CommandReceiverActor.scala:93) ~[isc-core-2.0.15.jar:?]
	at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251) ~[scala-library-2.11.7.jar:?]
	at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249) ~[scala-library-2.11.7.jar:?]
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.11.7.jar:?]
	at com.edifecs.epp.isc.core.dispatcher.ISCDispatcher$$anon$1$$anon$2.run(ISCDispatcherConfigurator.scala:83) [isc-core-2.0.15.jar:?]
	at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:39) [akka-actor_2.11-2.4.11.jar:?]
	at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:409) [akka-actor_2.11-2.4.11.jar:?]
	at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.11.7.jar:?]
	at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.11.7.jar:?]
	at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.11.7.jar:?]
	at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.11.7.jar:?]
	Suppressed: com.edifecs.epp.isc.exception.MessageException: Exception returned from message sent
	from command mlr.getProviderTaxIDs (? -> ppa-service)
		at com.edifecs.epp.isc.CommandCommunicator$$anonfun$com$edifecs$epp$isc$CommandCommunicator$$parseMessageResponse$1.apply(CommandCommunicator.scala:297) ~[isc-core-2.0.15.jar:?]
		at com.edifecs.epp.isc.CommandCommunicator$$anonfun$com$edifecs$epp$isc$CommandCommunicator$$parseMessageResponse$1.apply(CommandCommunicator.scala:288) ~[isc-core-2.0.15.jar:?]
		at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library-2.11.7.jar:?]
		at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.11.7.jar:?]
		at com.edifecs.epp.isc.core.dispatcher.ISCDispatcher$$anon$1$$anon$2.run(ISCDispatcherConfigurator.scala:83) [isc-core-2.0.15.jar:?]
		at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:39) [akka-actor_2.11-2.4.11.jar:?]
		at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:409) [akka-actor_2.11-2.4.11.jar:?]
		at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.11.7.jar:?]
		at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.11.7.jar:?]
		at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.11.7.jar:?]
		at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.11.7.jar:?]
Caused by: com.edifecs.epp.isc.exception.MessageException: <java.lang.IllegalStateException> Cannot overwrite a Cache's CacheManager.
	at com.hazelcast.client.cache.impl.ClientCacheProxySupport.setCacheManager(ClientCacheProxySupport.java:238) ~[?:?]
	at com.hazelcast.client.cache.impl.ClientCacheProxy.setCacheManager(ClientCacheProxy.java:93) ~[?:?]
	at com.hazelcast.client.cache.impl.HazelcastClientCacheManager.createCacheProxy(HazelcastClientCacheManager.java:115) ~[?:?]
	at com.hazelcast.cache.impl.AbstractHazelcastCacheManager.getCacheUnchecked(AbstractHazelcastCacheManager.java:234) ~[?:?]
	at com.hazelcast.cache.impl.AbstractHazelcastCacheManager.getCache(AbstractHazelcastCacheManager.java:210) ~[?:?]
	at com.hazelcast.cache.impl.AbstractHazelcastCacheManager.getCache(AbstractHazelcastCacheManager.java:65) ~[?:?]
	at org.springframework.cache.jcache.JCacheCacheManager.getMissingCache(JCacheCacheManager.java:129) ~[?:?]
	at org.springframework.cache.support.AbstractCacheManager.getCache(AbstractCacheManager.java:97) ~[?:?]
	at org.springframework.cache.interceptor.AbstractCacheResolver.resolveCaches(AbstractCacheResolver.java:89) ~[?:?]
	at org.springframework.cache.interceptor.CacheAspectSupport.getCaches(CacheAspectSupport.java:253) ~[?:?]
	at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.<init>(CacheAspectSupport.java:708) ~[?:?]
	at org.springframework.cache.interceptor.CacheAspectSupport.getOperationContext(CacheAspectSupport.java:266) ~[?:?]
	at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContexts.<init>(CacheAspectSupport.java:599) ~[?:?]
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:346) ~[?:?]
	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61) ~[?:?]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[?:?]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[?:?]
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367) ~[?:?]
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) ~[?:?]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[?:?]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[?:?]
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) ~[?:?]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[?:?]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[?:?]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) ~[?:?]
	at com.edifecs.fin.ppa.service.MLRService$$EnhancerBySpringCGLIB$$4c739ccd.getProviderTaxIDs(<generated>) ~[?:?]
	at com.edifecs.fin.ppa.handler.MLRhandler.getProviderTaxIDs(MLRhandler.java:68) ~[?:?]

Expected behavior
As per the documentation, we can use SPEL expression to distinguish the keys for two methods without params.

Additional context

@jerrinot
Copy link
Contributor

jerrinot commented Aug 1, 2020

Thank you for reporting the issue.

I am not sure whether it's caused by different methods/return types. It looks like a more generic race condition in Hazelcast code.
Particularly this and also this snippets look suspicious.

Let me investigate it a bit.

@jerrinot jerrinot self-assigned this Aug 1, 2020
jerrinot added a commit that referenced this issue Aug 1, 2020
@jerrinot
Copy link
Contributor

jerrinot commented Aug 1, 2020

indeed it looks like a bug. I prepared a fix, let's see what reviewers think of this.

once more thanks for reporting it!

vbekiaris pushed a commit to vbekiaris/hazelcast that referenced this issue Aug 3, 2020
vbekiaris added a commit to vbekiaris/hazelcast that referenced this issue Aug 3, 2020
Fixes hazelcast#17284 on 3.12.z branch

Backported from a58cce0
vbekiaris added a commit to vbekiaris/hazelcast that referenced this issue Aug 3, 2020
Fixes hazelcast#17284 on 3.12.z branch

Backported from a58cce0
vbekiaris added a commit to vbekiaris/hazelcast that referenced this issue Aug 3, 2020
Fixes hazelcast#17284 on 3.12.z branch

Backported from a58cce0
vbekiaris added a commit that referenced this issue Aug 3, 2020
Fixes #17284 on 3.12.z branch

Backported from a58cce0
vbekiaris pushed a commit that referenced this issue Aug 3, 2020
Fixes #17284

(cherry picked from commit a58cce0)
@mmedenjak mmedenjak added Module: ICache Source: Community PR or issue was opened by a community user Team: Core labels Aug 7, 2020
@mmedenjak mmedenjak modified the milestones: 4.0.3, 3.12.9 Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants