hierynomus / smbj

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

SMBClient connect times out after 5 seconds #769

Open cmcgowen opened 1 year ago

cmcgowen commented 1 year ago

With this code:

SMBClient client = new SMBClient(SmbConfig.builder()
                    .withSigningRequired(true)
                    .withDfsEnabled(true)
                    .withMultiProtocolNegotiate(true)
                    .withTransactTimeout(120, TimeUnit.SECONDS)
                    .build());

Connection connection = client.connect(remoteRepositoryInfo.hostname);

I am getting "java.net.SocketTimeoutException: connect timed out" 5 seconds after the call.

This is only happening when trying to connect to a specific machine. It works when connecting to different machine.

From the machine where the java code is running, I am able to connect to the share with NET USE, so the machine should be reachable.

I have tried using the hostname of the machine as well as the IP address in the call to connect() with the same results. I originally tried using JCIFS, and that was able to connect to the machine, but I ran into issues when trying to list the files in a shared folder, so I switched to smbj.

Is there something else that I'm missing?

hierynomus commented 1 year ago

Can you provide some detailed trace level logging for the connection attempt?

gascani commented 1 year ago

I've got exactly the same problem.

The stackstrace of the exception is:

[09/08/2023 01:13:00,224] [pool-2-thread-1] [INFO ] [SharedFolderUtility ][download ] ...start download from smb... [09/08/2023 01:13:05,226] [pool-2-thread-1] [ERROR ] [SharedFolderUtility ][download ] EX GENERIC msg=Connect timed out stack trace=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:139) at com.hierynomus.smbj.SMBClient.getEstablishedOrConnect(SMBClient.java:96) at com.hierynomus.smbj.SMBClient.connect(SMBClient.java:71) at com.sigmaspa.common.utility.filesync.common.utils.SharedFolderUtility.download(SharedFolderUtility.java:89) at com.sigmaspa.common.utility.filesync.common.download.Downloader.download(Downloader.java:198) at com.sigmaspa.common.utility.filesync.common.download.Downloader.download(Downloader.java:97) at com.sigmaspa.common.utility.filesync.agent.SigmaFilesyncAgent.execute(SigmaFilesyncAgent.java:417) at com.sigmaspa.common.utility.filesync.agent.SigmaFilesyncAgent.access$000(SigmaFilesyncAgent.java:72) at com.sigmaspa.common.utility.filesync.agent.SigmaFilesyncAgent$1.run(SigmaFilesyncAgent.java:160) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) at java.base/java.lang.Thread.run(Thread.java:832)

Is there a way to change the connection timeout? Thanks

guybmayor commented 8 months ago

Hey, I have got the same issue, have you solved it?

cliviu commented 2 months ago

Hi, same happens here in connect :

start connect time: 06:23:38,17 end connect time: 06:23:43,324

Caused by: java.net.SocketTimeoutException: Connect timed out at sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:551) ~[?:?] at sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602) ~[?:?] at java.net.Socket.connect(Socket.java:633) ~[?:?] at com.hierynomus.protocol.commons.socket.ProxySocketFactory.createSocket(ProxySocketFactory.java:87) ~[smbj-0.12.0.jar:0.12.0] at com.hierynomus.protocol.commons.socket.ProxySocketFactory.createSocket(ProxySocketFactory.java:63) ~[smbj-0.12.0.jar:0.12.0] at com.hierynomus.smbj.transport.tcp.direct.DirectTcpTransport.connect(DirectTcpTransport.java:95) ~[smbj-0.12.0.jar:0.12.0] at com.hierynomus.smbj.connection.Connection.connect(Connection.java:139) ~[smbj-0.12.0.jar:0.12.0] at com.hierynomus.smbj.SMBClient.getEstablishedOrConnect(SMBClient.java:96) ~[smbj-0.12.0.jar:0.12.0] at com.hierynomus.smbj.SMBClient.connect(SMBClient.java:71) ~[smbj-0.12.0.jar:0.12.0]