Receiving exception "Failed to connect to the server at ;host;:;port; and "connect timed out".

Receiving exception "Failed to connect to the server at ;host;:;port; and "connect timed out".

book

Article ID: KB0093531

calendar_today

Updated On:

Products Versions
TIBCO Enterprise Message Service -
Not Applicable -

Description

Resolution:
Application receives exception: javax.jms.JMSException: Failed to connect to the server at <host>:<port> and
"Linked Exception: connect timed out", while trying to connect to an EMS server.
The exception "connect timed out" is thrown from the java.net.Socket library.

====
javax.jms.JMSException: Failed to connect to the server at ssl://<host>:<port>:7222
        at com.tibco.tibjms.TibjmsxLinkTcp._createSocket(TibjmsxLinkTcp.java:819)
        at com.tibco.tibjms.TibjmsxLinkSSL.connect(TibjmsxLinkSSL.java:386)
        at com.tibco.tibjms.TibjmsConnection._create(TibjmsConnection.java:1304)
        at com.tibco.tibjms.TibjmsConnection.<init>(TibjmsConnection.java:4175)
        at com.tibco.tibjms.TibjmsTopicConnection.<init>(TibjmsTopicConnection.java:36)
        at com.tibco.tibjms.TibjmsxCFImpl._createImpl(TibjmsxCFImpl.java:191)
        at com.tibco.tibjms.TibjmsxCFImpl._createConnection(TibjmsxCFImpl.java:253)
        at com.tibco.tibjms.TibjmsTopicConnectionFactory.createTopicConnection(TibjmsTopicConnectionFactory.java:88)
        at tibjmsSSL.<init>(tibjmsSSL.java:159)
        at tibjmsSSL.main(tibjmsSSL.java:205)
##### Linked Exception:
java.net.SocketTimeoutException: connect timed out
        at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
=====

The EMS Java client API uses Socket.connect(SocketAddress endpoint, int timeout) to create a connection to an EMS server.
The exception is thrown if the timeout expires before connecting. By default the timeout is 3 seconds.
The timeout (in milliseconds) can be set through the system property -Dtibco.tibjms.socket.connect.timeout.  

The exception occurs because of the the following:

- Network is disconnected.
- Server machine is down.
- Server port (tcp or ssl) is blocked by firewall.
- Server or client machine is busy.

After a client sends a "SYN" packet to the server, it does not receive any packet (either "RST" or "SYN-ACK") from the server. By default, the EMS client library tries to connect to the server two times 500ms apart and gives up if not successful. You can configure connect_attempt_count/connect_attempt_delay so that the application can still connect, for example, when the network is disconnected temporarily.The configuration can be made ed in the following locations:

1). In factories.conf:

connect_attempt_count = 20
connect_attempt_delay = 500

2). In the application:

factory.setConnAttemptCount(20);
factory.setConnAttemptDelay(500);

3). Passed as a system property:

-Dtibco.tibjms.connect.attempts=20,500

If this does not solve the issue, increase the socket timeout. Example: -Dtibco.tibjms.socket.connect.timeout=10000

The optimum value of parameters should be determined by testing. Refer also to the EMS User's Guide -> Chapter 7 Using the Configuration Files : Using Other Configuration Files -> factories.conf and Chapter 19 Fault Tolerance : Configuring Clients for Fault-Tolerant Connections.

Issue/Introduction

Receiving exception "Failed to connect to the server at ;host;:;port; and "connect timed out".

Additional Information

EMS User's Guide
KB 37408