Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -4560,7 +4560,13 @@ void replicationHandlePrimaryDisconnection(void) {
moduleFireServerEvent(VALKEYMODULE_EVENT_PRIMARY_LINK_CHANGE, VALKEYMODULE_SUBEVENT_PRIMARY_LINK_DOWN, NULL);

server.primary = NULL;
server.repl_state = REPL_STATE_CONNECT;
/* freeClient(primary) can be deferred via freeClientAsync when the client
* has pending IO (since #3324). By the time we run in that deferred context,
Comment thread
ranshid marked this conversation as resolved.
Outdated
* replicationUnsetPrimary()/replicationSetPrimary() may have already
* finalized replication state. If primary_host is NULL, a deliberate unset
* is in progress (or complete), so avoid setting REPL_STATE_CONNECT which
* would make replicationCron call connectWithPrimary() with a NULL host. */
server.repl_state = server.primary_host ? REPL_STATE_CONNECT : REPL_STATE_NONE;
server.repl_down_since = server.unixtime;
/* We lost connection with our primary, don't disconnect replicas yet,
* maybe we'll be able to PSYNC with our primary later. We'll disconnect
Expand Down Expand Up @@ -5268,8 +5274,14 @@ void replicationCron(void) {

/* Check if we should connect to a PRIMARY */
if (server.repl_state == REPL_STATE_CONNECT) {
serverLog(LL_NOTICE, "Connecting to PRIMARY %s:%d", server.primary_host, server.primary_port);
connectWithPrimary();
if (server.primary_host) {
serverLog(LL_NOTICE, "Connecting to PRIMARY %s:%d", server.primary_host, server.primary_port);
connectWithPrimary();
} else {
serverLog(LL_WARNING,
"REPL_STATE_CONNECT with primary_host == NULL; resetting to REPL_STATE_NONE");
server.repl_state = REPL_STATE_NONE;
Comment thread
ranshid marked this conversation as resolved.
}
}

/* Send ACK to primary from time to time.
Expand Down
1 change: 1 addition & 0 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ static int connTLSConnect(connection *conn_,
unsigned char addr_buf[sizeof(struct in6_addr)];

if (conn->c.state != CONN_STATE_NONE) return C_ERR;
if (addr == NULL) return C_ERR;
ERR_clear_error();

/* Check whether addr is an IP address, if not, use the value for Server Name Indication */
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/wait.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ tags {"wait aof network external:skip"} {
set rd [valkey_deferring_client -1]
$rd incr foo
$rd read
$rd waitaof 0 1 0
$rd waitaof 0 1 10000
wait_for_blocked_client -1
$replica replicaof $master_host $master_port
assert_equal [$rd read] {1 1}
Expand Down
Loading