ServiceStack / Issues

Issue Tracker for the commercial versions of ServiceStack
11 stars 6 forks source link

ServiceStack - Only one usage of each socket address is normally permitted #709

Closed ARTRANAV closed 4 years ago

ARTRANAV commented 4 years ago

Hi,

We are having this problem but we don't know why it is.

ServiceStack.Redis.RedisException: INTERNAL_IP:PORT ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted INTERNAL_IP:PORT at System.Net.Sockets.Socket.Connect(IPAddress[] addresses, Int32 port) at System.Net.Sockets.Socket.Connect(String host, Int32 port) at ServiceStack.Redis.RedisNativeClient.Connect() at ServiceStack.Redis.RedisNativeClient.TryConnectIfNeeded() at ServiceStack.Redis.RedisNativeClient.AssertConnectedSocket() --- End of inner exception stack trace --- at ServiceStack.Redis.RedisNativeClient.AssertConnectedSocket() at ServiceStack.Redis.RedisNativeClient.AssertServerVersionNumber() at ServiceStack.Redis.RedisClient.GetServerRole() at ServiceStack.Redis.RedisResolver.CreateRedisClient(RedisEndpoint config, Boolean master) at ServiceStack.Redis.RedisManagerPool.GetClient()

We currently have an application working on IIS (Microsoft Internet Information Services). This application use REDIS cache and it is working simultaneously on 2 balanced servers with NLB (Microsoft Network Load Balancing). Any IIS node can write/retrieve cache keys stored in REDIS (ServiceStack).

We instantiate the REDIS client as follows:

   public ServiceStackRedisCache(IOptions<RedisCacheConfiguration> optionsAccessor)
   {
       if (optionsAccessor == null)
       {
           throw new ArgumentNullException(nameof(optionsAccessor));
       }

       _options = optionsAccessor.Value;

       var host = $"{_options.Password}@{_options.Host}:{_options.Port}";
       RedisConfig.VerifyMasterConnections = false;
       _redisManager = new RedisManagerPool(host);
   }

We do not create a new instance for Redis Client for each read or write operation. We only instantiate the class in the start application. Obviously, each node create a new instance for Redis Client.

What may be the reason of this problem?

Thanks in advance!

mythz commented 4 years ago

We've never seen this Exception before, I'm assuming it's the redis-server host you're trying to connect to. Are you connecting directly to a redis server instance or something else?

ARTRANAV commented 4 years ago

Yes, I connect directly to a Redis server instance, from a Windows computer to a Linux (Redis) one. I don't know where is the issue, the error is not very clarifying.

mythz commented 4 years ago

This is an internal .NET Exception from .NET's Socket class where it's unable to establish a TCP Socket connection.

Maybe you're trying to make a connection to a Redis SSL endpoint, can you try adding ?ssl=true to your connection string to see if it makes a difference?

var host = $"{_options.Password}@{_options.Host}:{_options.Port}?ssl=true";
mythz commented 4 years ago

Closing issue as wont be able to do anything without a repro. If you can publish a stand-alone repro on GitHub and link to it here I can investigate further.