From 5412d36b4f4576c9ba116883f47d0291d667eeac Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 25 Nov 2024 12:16:22 +0800 Subject: [PATCH] Save open's errno when opening temp rdb fails to prevent it from being modified Apparently on Mac, sleep will modify errno to ETIMEDOUT, and then it prints the misleading message: Operation timed out. Signed-off-by: Binbin --- src/replication.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/replication.c b/src/replication.c index dcf7ee3f8c..7785f3999c 100644 --- a/src/replication.c +++ b/src/replication.c @@ -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;