redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.31k stars 1.19k forks source link

Connect Sentinel via TLS doesn't update servername for Redis had picked #1832

Open anhhai2810 opened 11 months ago

anhhai2810 commented 11 months ago
const config_sentinel = {
    sentinels: sentinels,
    sentinelPassword: '123456',
    sentinelTLS: {
        ca: 'cert',
        rejectUnauthorized: false,
        servername: 'sentinel-pro.svc.local'
    },
    password: '123456',
    name: 'mymaster',
    role: 'master',
    enableTLSForSentinelMode: true,
    tls:  {
        ca: 'cert',
        rejectUnauthorized: false,
        servername: 'redis-master-pro.svc.local'
    },
}

We have 1 Master and 2 slaves When Sentinel pick a node Redis to create a connection with TLS. At that time we can not use "config_sentinel.tls.servername" because server info may different to our config. So, i try modify at "node_modules\ioredis\built\connectors\SentinelConnector\index.js":

if (this.options.enableTLSForSentinelMode && this.options.tls) {
                    debug("Update TLS servername >>>", resolved.host);
                    **this.options.tls.servername = resolved.host;**
                    Object.assign(resolved, this.options.tls);
                    this.stream = (0, tls_1.connect)(resolved);
                    this.stream.once("secureConnect", this.initFailoverDetector.bind(this));

I hope this issue can be fixed from next Pull Request!

Thanks!