.NET: RabbitmqClient ConnectFactory timeout settings appear to be ignored

2,041 views
Skip to first unread message

Rowland Watkins

unread,
Jul 26, 2018, 4:08:48 AM7/26/18
to rabbitmq-users
Hi folks,

I'm attempting to wrap a RabbitMQ client inside a C# Windows Service (using Topshelf). I'd like the service to fail hard quickly in the event it cannot connect to a RabbitMQ instance. However, even after setting various timeouts to less than 10 secs, the service will cheerfully run for 20 seconds before timing out and throwing BrokerUnreachableException. My ConnectionFactory is as follows:

var factory = new ConnectionFactory(){
   
HostName = "localhost",
   
UserName = "blah",
   
Password = "blah",
   
RequestedConnectionTimeout = 3000,
   
AutomaticRecoveryEnabled = false,
    UseBackgroundThreadsForIO = false,
   
ContinutationTimeout =
Timespan.FromSeconds(3),
   
HandshakeContinutationTimeout = Timespan.FromSeconds(3),
   
SocketReadTimeout = 3000,
   
SocketWriteTimeout = 3000
};

var connection = factory.CreateConnection();

The above code will eventually (after 20 seconds) throw  BrokerUnreachableException with inner exceptions AggregationException and ConnectionFailureException and SocketException.

Any tips for how I might throw these exceptions even sooner? Many thanks!

Cheers,

Rowland

Michael Klishin

unread,
Jul 26, 2018, 4:18:32 AM7/26/18
to rabbitm...@googlegroups.com
The client will reconfigure socket timeouts to be higher than the heartbeat timeout value [1][2]
since not doing so will make the heartbeat value effectively useless. That's my best guess without a traffic capture.
Heartbeat values < 5 seconds are not recommended because of the risk of false positives.

When there is no node running, however, an exception should be thrown immediately since the target host will "actively refuse"
the connection to a port nothing is bound to.


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Rowland Watkins

unread,
Jul 26, 2018, 5:59:15 AM7/26/18
to rabbitmq-users
Hi Michael,

Thanks for your reply! Ok, so it appears I was actually using an IP and not localhost. When I replaced the IP address with localhost BrokerUnreachableException gets thrown immediately, as we would expect. Also, if the IP address is reachable, BrokerUnreachableException is thrown immediately, but if the IP is not reachable then we get this other timeout.

Cheers,

Rowland
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Michael Klishin

unread,
Jul 26, 2018, 11:21:21 AM7/26/18
to rabbitm...@googlegroups.com
There can potentially be even more timeout settings in the .NET TCP socket API we use ;)
but I am not an expert in that area.

When you use hostnames instead of IP addresses there's an extra step: hostname resolution, which RabbitMQ client
does not explicitly perform. There may be a way to globally control resolution timeouts in .NET, again, sadly I'm not a .NET
expert or even regular user so I don't know.

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages