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

HazelcastInstance not shutdown on close if config location is not set #7606

Closed
snicoll opened this issue Feb 25, 2016 · 8 comments

Comments

Projects
None yet
4 participants
@snicoll
Copy link
Contributor

commented Feb 25, 2016

If you create a javax.cache.CacheManager with the default settings, the underlying HazelcastInstance is not shutdown when one call close on the CacheManager.

Tracking it down in HazelcastServerCacheManager, it looks like it is only disposed if a config location was set.

What's the rationale for that check? How does it translate to the JSR-107 World?

@jerrinot

This comment has been minimized.

Copy link
Contributor

commented Feb 25, 2016

@snicoll: thanks for reporting this. let's see what' the reason for this.

@serkan-ozal

This comment has been minimized.

Copy link
Contributor

commented Feb 25, 2016

@snicoll The default hazelcast instance is shutdown by CachingProvider (on close) not by CacheManager. Because the default instance can be shared between multiple CacheManagers with default URI.

@snicoll

This comment has been minimized.

Copy link
Contributor Author

commented Feb 25, 2016

Thanks for the quick reply. What would be your advice to dispose that HazelcastInstance in test then? I tried to shutdown it myself in a finally statement but another test that is working on the same setup broke with the following exception:

Caused by: javax.cache.CacheException: Error opening URI [hazelcast]
    at com.hazelcast.cache.impl.AbstractHazelcastCachingProvider.getCacheManager(AbstractHazelcastCachingProvider.java:98)
    at com.hazelcast.cache.impl.AbstractHazelcastCachingProvider.getCacheManager(AbstractHazelcastCachingProvider.java:127)
    at com.hazelcast.cache.HazelcastCachingProvider.getCacheManager(HazelcastCachingProvider.java:156)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.createCacheManager(JCacheCacheConfiguration.java:106)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.jCacheCacheManager(JCacheCacheConfiguration.java:85)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$2c6bb192.CGLIB$jCacheCacheManager$1(<generated>)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$2c6bb192$$FastClassBySpringCGLIB$$2bfddc3a.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:355)
    at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration$$EnhancerBySpringCGLIB$$2c6bb192.jCacheCacheManager(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 108 more
Caused by: com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
    at com.hazelcast.instance.TerminatedLifecycleService.addLifecycleListener(TerminatedLifecycleService.java:40)
    at com.hazelcast.cache.impl.AbstractHazelcastCacheManager.registerLifecycleListener(AbstractHazelcastCacheManager.java:299)
    at com.hazelcast.cache.impl.AbstractHazelcastCacheManager.<init>(AbstractHazelcastCacheManager.java:102)
    at com.hazelcast.cache.impl.HazelcastServerCacheManager.<init>(HazelcastServerCacheManager.java:58)
    at com.hazelcast.cache.impl.HazelcastServerCachingProvider.createHazelcastCacheManager(HazelcastServerCachingProvider.java:82)
    at com.hazelcast.cache.impl.HazelcastServerCachingProvider.createHazelcastCacheManager(HazelcastServerCachingProvider.java:42)
    at com.hazelcast.cache.impl.AbstractHazelcastCachingProvider.getCacheManager(AbstractHazelcastCachingProvider.java:95)
    ... 122 more
@snicoll

This comment has been minimized.

Copy link
Contributor Author

commented Feb 25, 2016

FYI, I've used Caching.getCachingProvider(cachingProviderFqn).close(); and it seem to do the trick. That exception above is puzzling though. It looks like Hazelcast doesn't figure out that the shared instance has been closed.

snicoll added a commit to spring-projects/spring-boot that referenced this issue Feb 25, 2016

Cleanup HazelcastInstance in test
If a JCache provider is started with hazelcast and the default settings,
the underlying `HazelcastInstance` is disposed at the end of the
process, not when the `CacheManager` is closed.

This commit fixes the only test that use such setup.

See also hazelcast/hazelcast#7606

Closes gh-5209
@serkan-ozal

This comment has been minimized.

Copy link
Contributor

commented Feb 25, 2016

yes, I advice close the instance through CachingProvider on test's teardown.

@serkan-ozal serkan-ozal self-assigned this Feb 25, 2016

@ssi-hu-balint-balku

This comment has been minimized.

Copy link

commented Jun 7, 2016

although it is closed now, i have a similar issue with Hazelcast 3.6. we're creating client instances by passing the instance name. this way HazelcastClientCachingProvider.hazelcastInstance will not be set, thus a call later to HazelcastClientCachingProvider.close() will not close any instances - subsequent calls to CacheManager.close() will not close the instances as discussed above, and AbstractHazelcastCachingProvider.shutdownHazelcastInstance() will not close it either as the reference was not set earlier.

is this the desired behavior? we're using Hazelcast with JSR107 JCache annotations and would need a way to properly close all the allocated resources once our java bean cache implementations get closed/destroyed.

@serkan-ozal

This comment has been minimized.

Copy link
Contributor

commented Jun 8, 2016

Hi @ssi-hu-balint-balku,

You can get a client instance specific CacheManager by HazelcastClientCachingProvider.createCachingProvider(HazelcastInstance) by giving your client instance. By this way, all CacheManagers retrieved through this CachingProvider (and caches over retrieved CacheManagers) will use your client instance.

So when you call cachingProvider.close(), it shutdowns underlying client instance (your client instance in this case).

@ssi-hu-balint-balku

This comment has been minimized.

Copy link

commented Jun 8, 2016

hi @serkan-ozal,

the trick is we're using multiple CachingProviders in our code and are switching between them runtime. we can of course change our code based on your suggestion, but i'm afraid that would only work if we'd use the same instance for all our Hazelcast-based caches. right now we're creating multiple HazelcastInstances for all our CachingProviders. are you suggesting creating a single HazelcastInstance and use it for all CachingProviders instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.