Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor repldbfd leak in updateReplicasWaitingBgsave if fstat fails #1226

Merged
merged 1 commit into from
Oct 27, 2024
Merged
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
16 changes: 13 additions & 3 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,7 @@ void updateReplicasWaitingBgsave(int bgsaveerr, int type) {
client *replica = ln->value;

if (replica->repl_state == REPLICA_STATE_WAIT_BGSAVE_END) {
int repldbfd;
struct valkey_stat buf;

if (bgsaveerr != C_OK) {
Expand Down Expand Up @@ -1790,17 +1791,26 @@ void updateReplicasWaitingBgsave(int bgsaveerr, int type) {
}
replica->repl_start_cmd_stream_on_ack = 1;
} else {
if ((replica->repldbfd = open(server.rdb_filename, O_RDONLY)) == -1 ||
valkey_fstat(replica->repldbfd, &buf) == -1) {
repldbfd = open(server.rdb_filename, O_RDONLY);
if (repldbfd == -1) {
freeClientAsync(replica);
serverLog(LL_WARNING, "SYNC failed. Can't open/stat DB after BGSAVE: %s", strerror(errno));
serverLog(LL_WARNING, "SYNC failed. Can't open DB after BGSAVE: %s", strerror(errno));
continue;
}
if (valkey_fstat(repldbfd, &buf) == -1) {
freeClientAsync(replica);
serverLog(LL_WARNING, "SYNC failed. Can't stat DB after BGSAVE: %s", strerror(errno));
close(repldbfd);
continue;
}
replica->repldbfd = repldbfd;
replica->repldboff = 0;
replica->repldbsize = buf.st_size;
replica->repl_state = REPLICA_STATE_SEND_BULK;
replica->replpreamble = sdscatprintf(sdsempty(), "$%lld\r\n", (unsigned long long)replica->repldbsize);

/* When repl_state changes to REPLICA_STATE_SEND_BULK, we will release
* the resources in freeClient. */
connSetWriteHandler(replica->conn, NULL);
if (connSetWriteHandler(replica->conn, sendBulkToReplica) == C_ERR) {
freeClientAsync(replica);
Expand Down
Loading