I have one Hazelcast server and Hazelcast client but when I shutdown client and restart the client it is giving me below error:
Exception during initial connection to [localhost]:5701: com.hazelcast.core.HazelcastException: java.net.SocketException: Address already in use: no further information to address localhost/127.0.0.1:5701
My Server code is below:
@Bean
public HazelcastInstance hazelcastInstance() {
try {
Config config = new Config();
config.getNetworkConfig().setPort(5701)
.setPortAutoIncrement( true ).setPortCount(10);
config.setClusterName("abc");
config.setInstanceName("abc");
MapConfig mapConfig = new MapConfig();
mapConfig.setName("abc");
config.addMapConfig(mapConfig);
hazelCastInstance = Hazelcast.newHazelcastInstance(config);
return hazelCastInstance;
}catch (Exception e) {
e.printStackTrace();
return null;
}
}
and my client code is below:
ClientConfig clientConfig = new ClientConfig();
clientConfig.setClusterName("abc");
clientConfig.getNetworkConfig().addAddress("localhost");
clientConfig.getNetworkConfig().setSmartRouting(true);
clientConfig.getNetworkConfig().addOutboundPortDefinition("5701-5720");
ClientConnectionStrategyConfig connectionStrategyConfig = clientConfig.getConnectionStrategyConfig();
ConnectionRetryConfig connectionRetryConfig = connectionStrategyConfig.getConnectionRetryConfig();
connectionRetryConfig.setInitialBackoffMillis(1000)
.setMaxBackoffMillis(60000)
.setMultiplier(2)
.setClusterConnectTimeoutMillis(1000)
.setJitter(0.2);
HazelcastClient hc = HazelcastClient.newHazelcastClient(clientConfig);
While shutting down client I am calling hc.shutdown(). But when restarting client it is giving me above error. Please help me to solve this issue.
Below in the logs for this that I am getting:
java.net.SocketException: Address already in use: no further information
to address localhost/127.0.0.1:5701
18-Jun-2021 13:13:16.811 INFO [localhost-startStop-1] com.hazelcast.client.impl.connection.ClientConnectionManager.null hz.client_1 [APP] [4.2] Trying to connect to [localhost]:5703
18-Jun-2021 13:14:16.908 WARNING [localhost-startStop-1] com.hazelcast.client.impl.connection.tcp.TcpClientConnection.null hz.client_1 [APP] [4.2] ClientConnection{alive=false, connectionId=1, channel=NioChannel{/127.0.0.1:5703->localhost/127.0.0.1:5703}, remoteAddress=null, lastReadTime=2021-06-18 13:13:16.897, lastWriteTime=2021-06-18 13:13:16.896, closedTime=2021-06-18 13:14:16.905, connected server version=null} closed. Reason: Failed to authenticate connection
java.util.concurrent.TimeoutException
at com.hazelcast.client.impl.spi.impl.ClientInvocationFuture.newTimeoutException(ClientInvocationFuture.java:63)
at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:656)
at com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager.authenticateOnCluster(TcpClientConnectionManager.java:857)
at com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager.getOrConnectToAddress(TcpClientConnectionManager.java:594)
at com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager.lambda$doConnectToCandidateCluster$3(TcpClientConnectionManager.java:490)
at com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager.connect(TcpClientConnectionManager.java:444)
at com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager.doConnectToCandidateCluster(TcpClientConnectionManager.java:490)
at com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager.doConnectToCluster(TcpClientConnectionManager.java:406)
at com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager.connectToCluster(TcpClientConnectionManager.java:367)
at com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager.start(TcpClientConnectionManager.java:316)
at com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl.start(HazelcastClientInstanceImpl.java:369)
at com.hazelcast.client.HazelcastClient.constructHazelcastClient(HazelcastClient.java:460)
at com.hazelcast.client.HazelcastClient.newHazelcastClientInternal(HazelcastClient.java:416)
at com.hazelcast.client.HazelcastClient.newHazelcastClient(HazelcastClient.java:136)
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:498)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1706)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1645)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4699)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5165)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1125)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1859)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
18-Jun-2021 13:14:16.927 WARNING [localhost-startStop-1] com.hazelcast.client.impl.connection.ClientConnectionManager.null hz.client_1 [APP] [4.2] Exception during initial connection to [localhost]:5703: com.hazelcast.core.HazelcastException: java.util.concurrent.TimeoutException
18-Jun-2021 13:14:16.944 INFO [localhost-startStop-1] com.hazelcast.client.impl.connection.ClientConnectionManager.null hz.client_1 [APP] [4.2] Trying to connect to [localhost]:5702
18-Jun-2021 13:14:18.991 WARNING [localhost-startStop-1] com.hazelcast.client.impl.connection.ClientConnectionManager.null hz.client_1 [APP] [4.2] Exception during initial connection to [localhost]:5702: com.hazelcast.core.HazelcastException: java.net.SocketException: Connection refused: no further information to address localhost/127.0.0.1:5702
18-Jun-2021 13:14:18.993 WARNING [localhost-startStop-1] com.hazelcast.client.impl.connection.ClientConnectionManager.null hz.client_1 [APP] [4.2] Unable to get live cluster connection, cluster connect timeout (1000 ms) is reached. Attempt 1.
18-Jun-2021 13:14:18.999 INFO [localhost-startStop-1] com.hazelcast.client.impl.connection.ClientConnectionManager.null hz.client_1 [APP] [4.2] Unable to connect to any address from the cluster with name: APP. The following addresses were tried: [[localhost]:5702, [localhost]:5703, [localhost]:5701]
18-Jun-2021 13:14:19.008 INFO [localhost-startStop-1] com.hazelcast.core.LifecycleService.null hz.client_1 [APP] [4.2] HazelcastClient 4.2 (20210324 - 405cfd1) is SHUTTING_DOWN
18-Jun-2021 13:14:19.024 INFO [localhost-startStop-1] com.hazelcast.core.LifecycleService.null hz.client_1 [APP] [4.2] HazelcastClient 4.2 (20210324 - 405cfd1) is SHUTDOWN