Connection Timed Out. Why

What is a connection timeout during a http request

I will try to answer it a little bit more informally.

Connection timeout - is a time period within which a connection between a client and a server must be established. Suppose that you navigate your browser (client) to some website (server). What happens is that your browser starts to listen for a response message from that server but this response may never arrive for various reasons (e.g. server is offline). So if there is still no response from the server after X seconds, your browser will 'give up' on waiting, otherwise it might get stuck waiting for eternity.

Request timeout - as in the previous case where client wasn't willing to wait for response from server for too long, server is not willing to keep unused connection alive for too long either. Once the connection between server and client has been established, client must periodically inform server that it is still there by sending information to that server. If client fails to send any information to server in a specified time, server simply drops this connection as it thinks that client is no longer there to communicate with it (why wasting resources meaninglessly).

Time to live (TTL) - is a value specified inside of a packet that is set when the packet is created (usually to 255) that tells how long the packet can be left alive in a network. As this packet goes through the network, it arrives at routers that sit on the path between the packet's origin and its destination. Each time the router resends the packet, it also decrements its TTL value by 1 and if that value drops to 0, instead of resending the packet, router simply drops it as the packet is not supposed to live any longer. This mechanism is used to prevent network from flooding by data as each packet can live inside of it for only limited amount of 'time'.

Getting connection timeout instead of connection refused

Connection refused means service is not available at all. Refer to What can be the reasons of connection refused errors? post.

While Connection timeout is a time period within which a connection between a client and a server must be established. If not established for some reason your code throws this exception after some retries. https://itstillworks.com/server-connection-timeout-mean-22703.html could give you some insights.

localhost Vs remote:

on remote machine the machine is acting as a proxy i.e. the machine is running but underlying service is not accessible via the network. While on localhost say localhost:port is down connection is straight away refused and no attempt of wait for connection is done.(Though if your machine had been up with the service but connection establishing was unsuccessful you would have got timeout )

What is Connect Timeout in sql server connection string?

That is the timeout to create the connection, NOT a timeout for commands executed over that connection.

See for instance http://www.connectionstrings.com/all-sql-server-connection-string-keywords/
(note that the property is "Connect Timeout" (or "Connection Timeout"), not just "Timeout")


From the comments:

It is not possible to set the command timeout through the connection string. However, the SqlCommand has a CommandTimeout property (derived from DbCommand) where you can set a timeout (in seconds) per command.

Do note that when you loop over query results with Read(), the timeout is reset on every read. The timeout is for each network request, not for the total connection.

Connection timeout - AWS Ubuntu instance

Turns out the client's server instance was set up to be accessed from a limited IP address range which my own IP did not sit within.

Once the instance was changed to allow for IP’s from other locations, the connection succeeded as expected.

Many thanks to @stdunbar for the telnet pointer - this really helped debug what was going on here.

netcat getting connection timeout to specific ports alone

After adding outbound traffic rule in security groups this issue if fixed



Related Topics



Leave a reply



Submit