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
7 changes: 7 additions & 0 deletions src/server/replica.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ std::error_code Replica::HandleCapaDflyResp() {

// If we're syncing a different replication ID, drop the saved LSNs.
string_view master_repl_id = ToSV(LastResponseArgs()[0].GetBuf());

// If we tried to replicate from ourself return an error
if (master_repl_id == id_) {
LOG(WARNING) << "Can't connect to myself";
return make_error_code(errc::connection_aborted);
}

if (master_context_.master_repl_id != master_repl_id) {
if (absl::GetFlag(FLAGS_break_replication_on_master_restart) &&
!master_context_.master_repl_id.empty()) {
Expand Down
9 changes: 9 additions & 0 deletions tests/dragonfly/replication_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3657,3 +3657,12 @@ async def test_takeover_timeout_on_unresponsive_master(df_factory):
os.kill(master.proc.pid, signal.SIGCONT)
except Exception:
pass


async def test_replica_of_self(async_client):
port = async_client.connection_pool.connection_kwargs["port"]
with pytest.raises(redis.exceptions.ResponseError):
await async_client.execute_command(f"replicaof localhost {port}")

with pytest.raises(redis.exceptions.ResponseError):
await async_client.execute_command(f"replicaof 127.0.0.1 {port}")
Loading