Skip to content

Commit

Permalink
Avoid double close on repl_transfer_fd (#1349)
Browse files Browse the repository at this point in the history
The code is ok before 2de544c,
but now we will set server.repl_transfer_fd right after dfd was
initiated, and in here we have a double close error since dfd and
server.repl_transfer_fd are the same fd.

Also move the declaration of dfd/maxtries to a small scope to avoid
the confusion since they are only used in this code.

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin authored Nov 25, 2024
1 parent 2d48a39 commit 469d41f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -3414,7 +3414,6 @@ void dualChannelSetupMainConnForPsync(connection *conn) {
* establish a connection with the primary. */
void syncWithPrimary(connection *conn) {
char tmpfile[256], *err = NULL;
int dfd = -1, maxtries = 5;
int psync_result;

/* If this event fired after the user turned the instance into a primary
Expand Down Expand Up @@ -3684,6 +3683,7 @@ void syncWithPrimary(connection *conn) {

/* Prepare a suitable temp file for bulk transfer */
if (!useDisklessLoad()) {
int dfd = -1, maxtries = 5;
while (maxtries--) {
snprintf(tmpfile, 256, "temp-%d.%ld.rdb", (int)server.unixtime, (long int)getpid());
dfd = open(tmpfile, O_CREAT | O_WRONLY | O_EXCL, 0644);
Expand Down Expand Up @@ -3744,7 +3744,6 @@ void syncWithPrimary(connection *conn) {
/* Fall through to regular error handling */

error:
if (dfd != -1) close(dfd);
connClose(conn);
server.repl_transfer_s = NULL;
if (server.repl_rdb_transfer_s) {
Expand Down

0 comments on commit 469d41f

Please sign in to comment.