Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating 2nd connection to to Redis sentinel deployment using the same ConfigurationOptions instance fails with exception. #2233

Closed
madhub opened this issue Aug 29, 2022 · 1 comment · Fixed by #2242

Comments

@madhub
Copy link

madhub commented Aug 29, 2022

Creating 2nd connection to to Redis sentinel deployment using the same ConfigurationOptions instance fails with exception.

What is expected

Creating multiple connections with the same configuration instance should succeed.

What is observed

Failure with exception.
It looks like ConfigurationOptions instance passed to ConnectionMultiplexer.Connect is getting modified.

NOTE: Cloning ConfigurationOptions before connect also does not work.

Setup

Redis sentinel deployment with 2 slaves : Docker compose is attached.
OS : Ubuntu 20.04 LTS
.NET Core Version : 3.1.25
Redis NuGet Package Version: StackExchange.Redis 2.5.61

Start the sentinel cluster with default sentinel port

docker-compose up --scale redis-sentinel=3 -d

Run the below sample application.
Demo sample program

using System;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using StackExchange.Redis;

namespace netcore31
{
    class Program
    {
        static void Main(string[] args)
        {
            ConfigurationOptions configurationOptions =  ConfigurationOptions.Parse("localhost");
            configurationOptions.ServiceName = "mymaster";
            configurationOptions.Password = "str0ng_passw0rd";
            
            // 1st Connection
             using var firstConnection = ConnectionMultiplexer.Connect(configurationOptions);
             System.Console.WriteLine(firstConnection.GetStatus());
             IDatabase database = firstConnection.GetDatabase();
             database.StringSet("SomeKey","SomeValue");
             System.Console.WriteLine(database.StringGet("SomeKey"));

             
             // Eastblishing second connection 2nd throws exception
             using var secondConnection = ConnectionMultiplexer.Connect(configurationOptions);
            
             System.Console.WriteLine(secondConnection.GetStatus());
      }
  }
}

ConfigurationOptions object passed to ConnectionMultiplexer.Connect is getting changed hence

https://hub.docker.com/r/bitnami/redis-sentinel/

version: '2'

networks:
  app-tier:
    driver: bridge

services:
  redis:
    image: 'bitnami/redis:latest'
    environment:
      - REDIS_REPLICATION_MODE=master
      - REDIS_PASSWORD=str0ng_passw0rd
    networks:
      - app-tier
    ports:
      - '6379'
  redis-slave:
    image: 'bitnami/redis:latest'
    environment:
      - REDIS_REPLICATION_MODE=slave
      - REDIS_MASTER_HOST=redis
      - REDIS_MASTER_PASSWORD=str0ng_passw0rd
      - REDIS_PASSWORD=str0ng_passw0rd
    ports:
      - '6379'
    depends_on:
      - redis
    networks:
      - app-tier
  redis-sentinel:
    image: 'bitnami/redis-sentinel:latest'
    environment:
      - REDIS_MASTER_PASSWORD=str0ng_passw0rd
    depends_on:
      - redis
      - redis-slave
    ports:
      - '26379-26381:26379'
    networks:
      - app-tier
@NickCraver
Copy link
Collaborator

Alrighty 2 different issues here made this tricky to reason about but figured out what's happening. Fixes coming in #2242 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants