StackExchange / StackExchange/StackExchange.Redis

Redis Sentinel / Connection Leak

Open
#2,872 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.2k
Forks
1.6k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Redis Sentinel / Connection Leak

StackExchange.Redis (2.8.24) / OpenTelemetry.Instrumentation.StackExchangeRedis (1.9.0-beta.1)

Description

We are observing a connection leak in our production servers running redis sentinel.

Image

First of all, we checked that there is no ConnectionMultiplexer instance leak in our code base and in the dump.
Image

It turns out that when switching primary, the ConnectionMultiplexer's servers are cleared but the _serverSnapshot is not which causes duplicates (see below 1. figure) in the _serverSnapshot which pins PhysicalBridges (see below 2. and 3. figures).

  1. Duplicates in _serverSnapshot
    Image

  2. Leak of PhysicalBridge : 338
    Image

  3. Similar Retention (max 204) with a common path:
    Image

It seems that when adding a new endpoint to the _serverSnapshot the servers field has been previously cleared and duplicates appear in the _serverSnapshot field.

How to reproduce

  1. Setup a redis sentinel
  2. Create a ConnectionMultiplexer with StackExchange.Redis (2.8.24)
  3. Instrument with OpenTelemetry.Instrumentation.StackExchangeRedis (1.9.0-beta.1)
  4. Switch primary / replica over and over
  5. Observe the number of connections.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ConnectionMultiplexer.Sentinel.cs around line 415 and ConnectionMultiplexer.cs around line 905, then reproduce repeated Sentinel primary/replica switches using the listed StackExchange.Redis and OpenTelemetry versions. Trace how clearing servers and adding endpoints updates _serverSnapshot and retains PhysicalBridges. Done means repeated failovers no longer create duplicate snapshot entries or growing retained connections.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, redis
Domain
databases, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.