hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
713 stars 180 forks source link

Connectivity fails randomly one of the IP mapped to the host name is In-correct /Not Active #661

Open fazeem84 opened 3 years ago

fazeem84 commented 3 years ago

Hi @hierynomus and @pepijnve, I am getting connection time out error randomly when I tried to connect share folder from My Java program. When debugging the code found out that while for mapping host name to IP InetAddress.getAllByName("hostname") is been used and it returns two IP address one of which is not getting connected and the other one works fine is there any way to try to connect the working IP if the other one fails to connect?

java.net.SocketTimeoutException: Connect timed out at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:546) at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597) at java.base/java.net.Socket.connect(Socket.java:648) at com.hierynomus.protocol.commons.socket.ProxySocketFactory.createSocket(ProxySocketFactory.java:87) at com.hierynomus.protocol.commons.socket.ProxySocketFactory.createSocket(ProxySocketFactory.java:63) at com.hierynomus.smbj.transport.tcp.direct.DirectTcpTransport.connect(DirectTcpTransport.java:88) at com.hierynomus.smbj.connection.Connection.connect(Connection.java:135) at com.hierynomus.smbj.SMBClient.getEstablishedOrConnect(SMBClient.java:108) at com.hierynomus.smbj.SMBClient.connect(SMBClient.java:79)

fazeem84 commented 3 years ago

Can Anybody look into the issue?

rokkakasu commented 3 years ago

Hi @fazeem84 I believe your hostname has 2 ip addresses (May be a load balancer or IP address is getting changed often(i.e Elastic IP)) your issue is similar to https://github.com/hierynomus/smbj/issues/644 Resolution

  1. Upgrade to SMBJ version 0.11.3
  2. do a try catch and remove the server from the SMBClient serverlist. Ex. smbclient.getServerList().unregister()
  3. Reconnect.

feel free to close this issue.

Thanks, R Ramarajan.

danielhasugian commented 4 months ago

hi @rokkakasu

I follow your recommendation, but still failed. Could you provide a snip code.

thanks

hierynomus commented 4 months ago

I've tried to address this in #835, please see whether that works better