JayC
JayC

Reputation: 2292

What causes ch.ethz.ssh2.Connection to have a hang time?

I am currently using ch.ethz.ssh2.Connection to connect to my servers in java. sometimes it hangs on one server.(maybe like 10-15 seconds). I wanted to know what causes this hang time and how to avoid it.

Connection sample

    conn = new ch.ethz.ssh2.Connection(serverName);
    conn.connect();

    boolean isAuthenticated = conn.authenticateWithPassword(user, pass);
    logger.info("Connecting to " + server);

    if (isAuthenticated == false) {
        logger.info(server + " Please check credentials");              
    } 

    sess = conn.openSession();

   // I am connecting to over 200 servers and closing them. What would be the best practice to loop thru all these servers in the minimal time.

//some servers quickly connects, while some takes some time.
why does this happen?

Upvotes: 0

Views: 1092

Answers (2)

Kenster
Kenster

Reputation: 25439

My psychic debugging powers tell me that the server is doing a DNS lookup on the IP address of each client which connects. These DNS lookups are either taking a long time to complete, or they're failing entirely. The DNS lookup will block the authentication process until it finishes, successfully or not.

If the server is the OpenSSH server, this behavior is controlled by the sshd config "UseDNS" option.

Upvotes: 0

Robert
Robert

Reputation: 42710

The main question is: Is it a code problem, a network problem or a server problem.

A code problem can be debugged - unfortunately ch.ethz.ssh2.Connection does not have any logging possibility to detect what is going inside.

May be you should thing about switching the ssh library (or use it for some tests with the problematic servers). From my experience sshj is very useful.

If it is a network problem or a server problem you can check what is going on via Wireshark. If network packets are sent but the response is delayed the problem is not the used client-side code.

Upvotes: 1

Related Questions