[rabbitmq-discuss] TCP timeout is also happening for C# clients

Geoffrey Anderson mrcoder at yahoo.com
Tue May 13 22:54:52 BST 2008

FYI: I have found that a Hearbeat adjustment solves a BasicPublish() timeout problem
in dotnet clients.

OK guys thanks for guidance with diagnosing the connection problems.  It is solved
after I created an environment variable.

Now I progressed to the next problem (progress of sorts).  But I bring a solution

It all started when I called this line of code in my C# application:

mqModel.BasicPublish(mqTicket, mqExchange, mqRoutingKey, null,

The following exception is always thrown by it:

"AMQP close-reason, initiated by Library, code=541, text=\"Unexpected Exception\",
classId=0, methodId=0, cause=System.IO.IOException: Unable to read data from the
transport connection: A connection attempt failed because the connected party did
not properly respond after a period of time, or established connection failed
because connected host has failed to respond. --->
System.Net.Sockets.SocketException: A connection attempt failed because the
connected party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond\r\n   at
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size,
SocketFlags socketFlags)\r\n   at System.Net.Sockets.NetworkStream.Read(Byte[]
buffer, Int32 offset, Int32 size)\r\n   --- End of inner exception stack trace
---\r\n   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size)\r\n   at System.IO.Stream.ReadByte()\r\n   at
System.IO.BinaryReader.ReadByte()\r\n   at
RabbitMQ.Client.Impl.Frame.ReadFrom(NetworkBinaryReader reader)\r\n   at
RabbitMQ.Client.Impl.SocketFrameHandler_0_9.ReadFrame()\r\n   at
RabbitMQ.Client.Impl.ConnectionBase.MainLoopIteration()\r\n   at

So I looked around for solutions on the web, and discovered a "Java"-related
discussion recently in the mailing list:


The topic is TCP timeouts.

One possible solution to the "java" problem was proposed by manipulating the
heartbeat value of the connection factory:


But now I'm using C# rather than Java but the symptoms looked similar enough.

So I added a line of C# code to manipulate the heartbeat, just before it runs the

mqFactory.Parameters.RequestedHeartbeat = 50;

50 is a totally wild first guess but it actually works.

As a result of heartbeat modification my BasicPublish() call runs OK now.  I dont
get the exception, and the code continues flowing in the preferred way.

I just want you all to know that by appearances this is not strictly a java specific
problem but the discussion seemed to assume it was limited to java clients, or
limited to the Sun company's products.


Excerpt:  "A very interesting anomaly indeed, especially considering that it only 
seems to affect 1.5, not 1.4 or 1.6. However, as far as I can tell this 
behaviour can only occur with one CPU."


Actually I do have just one CPU core, it's true, but I do not code in java, just C#.

Here is what my log shows FWIW.

=INFO REPORT==== 13-May-2008::17:22:42 ===
Rolling persister log to "c:/Documents and

=INFO REPORT==== 13-May-2008::17:22:43 ===
started TCP listener on

=INFO REPORT==== 13-May-2008::17:23:01 ===
accepted TCP connection on from

=ERROR REPORT==== 13-May-2008::17:23:03 ===
error on TCP connection from

=INFO REPORT==== 13-May-2008::17:23:03 ===
closing TCP connection from

I now suspect there is a threading bug in the RabbitMQ stack and it is common to
both C# and java clients either by repetition of a mistaken code pattern, or by some
code layer in the RabbitMQ system which is shared in common by clients of both
languages.  Solutions applied in the application layer are probably not the best

Hope this helps the knowledge base.


More information about the rabbitmq-discuss mailing list