System.PlatformNotSupportedException: This platform does not support connecting sockets to DNS endpoints via the instance Connect and ConnectAsync methods, due to the potential for a host name to map to multiple IP addresses and sockets becoming invalid for use after a failed connect attempt. Use the static ConnectAsync method, or provide to the instance methods the specific IPAddress desired.
at System.Net.Sockets.Socket.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state)
at System.Net.Sockets.SocketTaskExtensions.<>c.<ConnectAsync>b__5_0(String targetHost, Int32 targetPort, AsyncCallback callback, Object state)
at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1,TArg2](Func`5 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
at System.Threading.Tasks.TaskFactory.FromAsync[TArg1,TArg2](Func`5 beginMethod, Action`1 endMethod, TArg1 arg1, TArg2 arg2, Object state)
at System.Net.Sockets.SocketTaskExtensions.ConnectAsync(Socket socket, String host, Int32 port)
at StackExchange.Redis.SocketManager.BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log)
at StackExchange.Redis.PhysicalConnection.BeginConnect(TextWriter log)
at StackExchange.Redis.PhysicalBridge.GetConnection(TextWriter log)
at StackExchange.Redis.ServerEndPoint..ctor(ConnectionMultiplexer multiplexer, EndPoint endpoint, TextWriter log)
at StackExchange.Redis.ConnectionMultiplexer.<ReconfigureAsync>d__119.MoveNext()
StackExchange.Redis.StrongName: 1.1.604-alpha
Ubuntu 16.04
netcore: 1.0.0-preview2-003121
This is not StackExchange.Redis issue, see https://github.com/dotnet/corefx/issues/8768 but there is a workaround , mongodb csharp driver encounter the same issue : https://jira.mongodb.org/browse/CSHARP-1736
Perhaps we should try/catch this and throw a more informative exception? The issue isn't going anywhere, at least for a while.
For anyone looking to see what the workaround is, it's just manually resolving the DNS:
//because of https://github.com/dotnet/corefx/issues/8768
var dnsTask = Dns.GetHostAddressesAsync(redis.GetValue<string>("host"));
var addresses = dnsTask.Result;
var connect = string.Join(",", addresses.Select(x => x.MapToIPv4().ToString() + ":" + redis.GetValue<int>("port")));
The worst part is I'm using the ASP.NET Caching library and this is in my service provider building :(
@NickCraver @adamhathcock well that doesn't help for hosted redis services on Azure for example.
Domain would be faulted: AuthenticationFailure on PING during connection attempts. I guess its because your SSL stuff is only valid for the domain name?!
Don't get me wrong, all my redis apps and tests with this client work perfectly fine on Ubuntu 14 for example as long as you use the IP address of a server which supports that.
But seems there is no workaround for that scenario when you cannot use an IP address?
I don't know about Azure but this works on AWS. I wouldn't know why it's different.
@NickCraver just found that this seems to be a duplicate of #410?
@adamhathcock What does work on AWS?
On Azure the following is not working: Using SSL + the (public) IP of the host to connect to it from outside a virtual network. Does that work on AWS?
To make it work on Azure, you either have to disable SSL and use the non-secured port (which is bad) + the public IP, or you use a virtual network and your services/clients have to be in the same network/visible to the redis instance, so that you are using the internal IP range + NO SSL again I guess (didn't test that, but I guess it would work).
The problem is, virtual networks are only available for the premium tier instances starting at 6GB => expensive to play with...
The DNS resolution to an IP works fine for AWS. I connect to the IP.
AWS has a similar restriction in that the Redis instance can't be exposed to the public internet directly. To use the redis locally I SSH tunnel to another instance in the VPC (virtual network) to get to the Redis instance if I want to.
@NickCraver this is small problem in docker-compose setups.
We have workaround taken from Mongo solution.
The new netstandard2.0 tooling will fix this across the board - there's been a lot of work put into Sockets in general for v2. Stay tuned, it's available soon (in preview now even) and allows all DNS connections as you'd expect.
I'd be curious if simply running on the .NET Core 2.0 preview resolves the issues here, it should.
I'll wait for release, thank you. I fed up with ms alpha-beta tooling, unfortunately.
@NickCraver Hijacking this thread but I am facing the same problem and I will report that simply using .NET Core 2.0 Preview 1 solves it, although that's not the solution I'd like to go with for now.
@NickCraver I am using dotnet core 2.0 , but the issue still persists . Anything else I need to do to resolve this :
"Error while storing value in cache.|This platform does not support
connecting sockets to DNS endpoints via the instance Connect and ConnectAsync methods, due to the potential for a host name to map to multiple
IP addresses and sockets becoming invalid for use after a failed connect attempt. Use the static ConnectAsync method, or provide to the instance methods the
specific IPAddress desired.
@rthadhani Which version are you running on specifically? This should be resolved when running on .NET Core 2.0+ bits.
No updates here so closing out - should be working on .NET Core 2.0, and I'm unable to reproduce any problems on Windows, Linux, or macOS.
Most helpful comment
For anyone looking to see what the workaround is, it's just manually resolving the DNS:
The worst part is I'm using the ASP.NET Caching library and this is in my service provider building :(