Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ void clusterUpdateMyselfFlags(void) {
void clusterUpdateMyselfAnnouncedPorts(void) {
if (!myself) return;
deriveAnnouncedPorts(&myself->tcp_port, &myself->tls_port, &myself->cport);
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG);
}

/* We want to take myself->ip in sync with the cluster-announce-ip option.
Expand Down Expand Up @@ -1050,6 +1051,7 @@ void clusterUpdateMyselfIp(void) {
} else {
myself->ip[0] = '\0'; /* Force autodetection. */
}
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2473,6 +2473,7 @@ static int updatePort(const char **err) {
listener->bindaddr_count = server.bindaddr_count;
listener->port = server.port;
listener->ct = connectionByType(CONN_TYPE_SOCKET);
clusterUpdateMyselfAnnouncedPorts();
if (changeListener(listener) == C_ERR) {
*err = "Unable to listen on this port. Check server logs.";
return 0;
Expand Down Expand Up @@ -2660,7 +2661,6 @@ int updateClusterFlags(const char **err) {
static int updateClusterAnnouncedPort(const char **err) {
UNUSED(err);
clusterUpdateMyselfAnnouncedPorts();
clearCachedClusterSlotsResponse();
return 1;
}

Expand Down Expand Up @@ -2719,6 +2719,7 @@ static int applyTLSPort(const char **err) {
listener->bindaddr_count = server.bindaddr_count;
listener->port = server.tls_port;
listener->ct = connectionByType(CONN_TYPE_TLS);
clusterUpdateMyselfAnnouncedPorts();
if (changeListener(listener) == C_ERR) {
*err = "Unable to listen on this port. Check server logs.";
return 0;
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/cluster/announced-endpoints.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,43 @@ start_cluster 2 2 {tags {external:skip cluster}} {
R 0 config set cluster-announce-bus-port 0
assert_match "*@$base_bus_port *" [R 0 CLUSTER NODES]
}

test "Test change port and tls-port on runtime" {
if {$::tls} {
set baseport [lindex [R 0 config get tls-port] 1]
} else {
set baseport [lindex [R 0 config get port] 1]
}
set count [expr [llength $::servers] + 1]
set used_port [find_available_port $baseport $count]

# We execute CLUSTER SLOTS command to trigger the `debugServerAssertWithInfo` in `clusterCommandSlots` function, ensuring
# that the cached response is invalidated upon updating any of port or tls-port.
R 0 CLUSTER SLOTS
R 1 CLUSTER SLOTS

# Set port or tls-port to ensure changes are consistent across the cluster.
if {$::tls} {
R 0 config set tls-port $used_port
} else {
R 0 config set port $used_port
}
# Make sure changes in myself node's view are consistent.
assert_match "*:$used_port@*" [R 0 CLUSTER NODES]
assert_match "*$used_port*" [R 0 CLUSTER SLOTS]
# Make sure changes in other node's view are consistent.
wait_for_condition 50 100 {
[string match "*:$used_port@*" [R 1 CLUSTER NODES]] &&
[string match "*$used_port*" [R 1 CLUSTER SLOTS]]
} else {
fail "Node port was not propagated via gossip"
}

# Restore the original configuration item value.
if {$::tls} {
R 0 config set tls-port $baseport
} else {
R 0 config set port $baseport
}
}
}
Loading