Skip to content

Commit

Permalink
Save open's errno when opening temp rdb fails to prevent it from bein…
Browse files Browse the repository at this point in the history
…g modified

Apparently on Mac, sleep will modify errno to ETIMEDOUT, and then it
prints the misleading message: Operation timed out.

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin committed Nov 25, 2024
1 parent 653d5f7 commit 5412d36
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -3684,13 +3684,18 @@ void syncWithPrimary(connection *conn) {

/* Prepare a suitable temp file for bulk transfer */
if (!useDisklessLoad()) {
/* We save the errno of open to prevent some systems from modifying it after
* the sleep call. For example, sleep in Mac will change errno to ETIMEDOUT. */
int saved_errno;
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);
if (dfd != -1) break;
saved_errno = errno;
sleep(1);
}
if (dfd == -1) {
errno = saved_errno;
serverLog(LL_WARNING, "Opening the temp file needed for PRIMARY <-> REPLICA synchronization: %s",
strerror(errno));
goto error;
Expand Down

0 comments on commit 5412d36

Please sign in to comment.