`void sentinelReconnectInstance(sentinelRedisInstance ri) { if (ri->link->disconnected == 0) return; if (ri->addr->port == 0) return; / port == 0 means invalid address. / instanceLink link = ri->link; mstime_t now = mstime();

if (now - ri->link->last_reconn_time < SENTINEL_PING_PERIOD) return;
ri->link->last_reconn_time = now;

/* Commands connection. */
if (link->cc == NULL) {
    link->cc = redisAsyncConnectBind(ri->addr->ip,ri->addr->port,NET_FIRST_BIND_ADDR);
    if (!link->cc->err && server.tls_replication &&
            (instanceLinkNegotiateTLS(link->cc) == C_ERR)) {
        sentinelEvent(LL_DEBUG,"-cmd-link-reconnection",ri,"%@ #Failed to initialize TLS");
        instanceLinkCloseConnection(link,link->cc);
    } else if (link->cc->err) {
        sentinelEvent(LL_DEBUG,"-cmd-link-reconnection",ri,"%@ #%s",
            link->cc->errstr);
        instanceLinkCloseConnection(link,link->cc);
    } else {
        link->pending_commands = 0;
        link->cc_conn_time = mstime();
        link->cc->data = link;
        redisAeAttach(server.el,link->cc);
        redisAsyncSetConnectCallback(link->cc,
                sentinelLinkEstablishedCallback);
        redisAsyncSetDisconnectCallback(link->cc,
                sentinelDisconnectCallback);
        sentinelSendAuthIfNeeded(ri,link->cc);
        sentinelSetClientName(ri,link->cc,"cmd");

        /* Send a PING ASAP when reconnecting. */
        sentinelSendPing(ri);
    }
}
/* Pub / Sub */
if ((ri->flags & (SRI_MASTER|SRI_SLAVE)) && link->pc == NULL) {
    link->pc = redisAsyncConnectBind(ri->addr->ip,ri->addr->port,NET_FIRST_BIND_ADDR);
    if (!link->pc->err && server.tls_replication &&
            (instanceLinkNegotiateTLS(link->pc) == C_ERR)) {
        sentinelEvent(LL_DEBUG,"-pubsub-link-reconnection",ri,"%@ #Failed to initialize TLS");
    } else if (link->pc->err) {
        sentinelEvent(LL_DEBUG,"-pubsub-link-reconnection",ri,"%@ #%s",
            link->pc->errstr);
        instanceLinkCloseConnection(link,link->pc);
    } else {
        int retval;

        link->pc_conn_time = mstime();
        link->pc->data = link;
        redisAeAttach(server.el,link->pc);
        redisAsyncSetConnectCallback(link->pc,
                sentinelLinkEstablishedCallback);
        redisAsyncSetDisconnectCallback(link->pc,
                sentinelDisconnectCallback);
        sentinelSendAuthIfNeeded(ri,link->pc);
        sentinelSetClientName(ri,link->pc,"pubsub");
        /* Now we subscribe to the Sentinels "Hello" channel. */
        retval = redisAsyncCommand(link->pc,
            sentinelReceiveHelloMessages, ri, "%s %s",
            sentinelInstanceMapCommand(ri,"SUBSCRIBE"),
            SENTINEL_HELLO_CHANNEL);
        if (retval != C_OK) {
            /* If we can't subscribe, the Pub/Sub connection is useless
             * and we can simply disconnect it and try again. */
            instanceLinkCloseConnection(link,link->pc);
            return;
        }
    }
}
/* Clear the disconnected status only if we have both the connections
 * (or just the commands connection if this is a sentinel instance). */
if (link->cc && (ri->flags & SRI_SENTINEL || link->pc))
    link->disconnected = 0;

} ` i am not pretty sure if this is a bug, but : link->cc = redisAsyncConnectBind(ri->addr->ip,ri->addr->port,NET_FIRST_BIND_ADDR); or link->pc = redisAsyncConnectBind(ri->addr->ip,ri->addr->port,NET_FIRST_BIND_ADDR); is executed , if redisAsyncConnectBind(...) return a NULL as a return value , then the link->cc-> and link->pc-> will cause a abort. so i think we should judge where link->cc or link->pc is NULL after calling redisAsyncConnectBind(...), before execute the following code.

Comment From: madolson

Hey @yulei1990, that seems right to me. Typically in redis many calls can't fail because it would crash, but this instance seems to actually return NULL. Do you want to fix it?