StackExchange / StackExchange/StackExchange.Redis
Extra connection open per ConnectionMultiplexer on clustered caches when hostname is used or cluster is behind a load balancer
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.2k
- Forks
- 1.6k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
We've noticed that when connecting to clustered caches there is a connection to the configured endpoint which is seemingly only used to discover the other endpoints in the cluster that stays open for the lifetime of the ConnectionMultiplexer even though there won't be operations sent through it.
This behavior occurs because the ip:port endpoints returned by cluster nodes don't match the hostname:port endpoints that are configured in the connection string. A similar problem happens if a load balanced port is configured for connecting to the cluster if the same port is not returned by cluster nodes.
One possible way of removing this unused connection seems to be disposing it and removing it from the servers hashtable and snapshot like with this commit https://github.com/JimRoberts-MS/StackExchange.Redis/commit/ccad0cd194cbdd1c8e6dfd0a17b6e19c59dee654 . Without being too familiar with the inner workings of the library I'm not sure if there's a better way to go about doing it so suggestions are welcome if this is a reasonable way of approaching it. At a high level the goals are to not keep around this extra connection, but allow it to be opened and used by (re)configuration scenarios where the cluster endpoints might have changed like if the dns record changes or some existing nodes are removed from the cluster.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing clustered-cache discovery from the ConnectionMultiplexer, focusing on the configured endpoint, the endpoints returned by cluster nodes, and the servers hashtable and snapshot. Review the linked commit for context. Done means the unused discovery connection is not retained, while it can still be opened for reconfiguration when cluster endpoints change.
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