[rabbitmq-discuss] ConnectionFactory.CreateConnection() exception when using IPv4 address

ewulf84 at gmail.com ewulf84 at gmail.com
Tue Apr 29 05:03:08 BST 2014


I have a straightforward issue: If you supply an IPv4 address to a new 
AmqpTcpEndpoint in an IPv6-enabled Windows environment (Windows7) then pass 
that endpoint to a connection factory it will not be able to create 
connections.  It seems that if the client environment supports IPv6 you 
have to use an IPv6 address or a hostname.  My sample code is running the 
3.3.0 RabbitMQ .Net client:

var factory = new ConnectionFactory() 
{
UserName = "eric",
Password = "pwd" 
};


// WORKS (ipv6 addr)
// var uri = new 
Uri("amqp-0-9://[2001:a9fe:3100:1:f06c:255a:43e2:1459]:5672");

// WORKS (hostname)
// var uri = new Uri("amqp-0-9://s6-2k8r2-3:5672");

// Times out (mapped ipv4 [socket is probably not dual-stack?])
// var uri = new Uri("amqp-0-9://[0:0:0:0:0:ffff:172.31.195.246]:5672");

// Throws a System.ArgumentException in CreateConnection()
var uri = new Uri("amqp-0-9://172.31.195.246:5672");

factory.Endpoint = new AmqpTcpEndpoint(uri);

using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("test", false, false, false, null);

string message = "Hello World";
var body = Encoding.UTF8.GetBytes(message);

channel.BasicPublish("", "hello", null, body);
Console.WriteLine(" [x] Sent {0}", message);
}
}

The problem appears to be in the way the SocketFrameHandler_0_9.ctor() 
determines the socket address family:

if (Socket.OSSupportsIPv6)
    {
        try
        {
            this.m_socket = socketFactory(AddressFamily.InterNetworkV6);
            this.Connect(this.m_socket, endpoint, timeout);
        }
        catch (ConnectFailureException)
        {
            this.m_socket = null;
        }
    }


This may not be the best way to determine whether to use an IPv6 socket or 
an IPv4 socket.  The ArgumentException which is getting thrown from down in 
the Socket's DoDnsCallback is not caught in the FrameHandler ctor and 
instead makes its way up to the caller.  You may want to consider 
IPAddress.TryParsing the host from the Amqp endpoint and then getting the 
address family from that.  It would probably be faster than this method, 
too.

As it stands I cannot figure out a workaround for this issue.  If the only 
way you can access a machine from an IPv6-enabled Windows box is via its 
IPv4 address you would appear to be out of luck.  In the .Net client, 
anyway.

Thanks,
Eric

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140428/c40c6063/attachment.html>


More information about the rabbitmq-discuss mailing list