[rabbitmq-discuss] Error: RabbitMQ.Client.ConnectionFactory.cs - "Only one usage of each socket address (protocol/network address/port) is normally permitted"

Tony Garnock-Jones tonyg at lshift.net
Tue Sep 1 15:43:07 BST 2009


Patrick Kenney wrote:
> am I not already already using the same socket?

You are not reusing the same socket. Every time you make the following call:

> new ConnectionFactory().CreateConnection("localhost:5672")

... you create a new connection factory, and then a new connection,
which involves creating and connecting a socket, and performing login
and connection parameter negotiation.

Every TCP socket you create, even once it is closed, stays allocated on
the system for about two minutes. This is a characteristic of TCP, and
happens on all operating systems and on all TCP-using applications. If
you have more than a few thousand (at most, tens of thousands) sockets
so registered, your local TCP stack will complain that no more sockets
are available -- just as you reported.

Also, every time you make the following call:

> conn.CreateModel()

... you create a new channel, which involves allocation of stateful
resources on both the server and client side.

We recommend that you

 - create a single connection (CreateConnection(...)) that you use
   for a long time, and

 - create a single channel/model (CreateModel()) that you use for a long
   time, one channel/model per thread (if you're using threads).

Regards,
  Tony
-- 
 [][][] Tony Garnock-Jones     | Mob: +44 (0)7905 974 211
   [][] LShift Ltd             | Tel: +44 (0)20 7729 7060
 []  [] http://www.lshift.net/ | Email: tonyg at lshift.net




More information about the rabbitmq-discuss mailing list