Skip to content

Commit 2df6f21

Browse files
nitaicaroNitai Carovalkey-review-bot[bot]
authored
Use a unique temp file name for forkless save (#4528)
Ensures temp file uniqueness for forkless save temp file. --------- Signed-off-by: Nitai Caro <caronita@amazon.com> Signed-off-by: nitaicaro <42576749+nitaicaro@users.noreply.github.com> Co-authored-by: Nitai Caro <caronita@amazon.com> Co-authored-by: valkey-review-bot[bot] <282604435+valkey-review-bot[bot]@users.noreply.github.com>
1 parent c37f673 commit 2df6f21

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/forkless.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static void forklessSaveCloseSnapshotFile(void *args[]) {
194194
}
195195

196196
if (saveInfo->terminated || saveInfo->err_code != C_OK) {
197-
rdbRemoveTempFile(getpid(), 0);
197+
bg_unlink(saveInfo->temp_file);
198198
}
199199
sdsfree(saveInfo->temp_file);
200200
sdsfree(saveInfo->final_file);
@@ -297,8 +297,11 @@ int forklessSaveToDisk(const char *filename) {
297297

298298
server.stat_rdb_saves++;
299299

300+
/* Use a forkless-specific name with a unique counter so the temp file can't
301+
* collide with a fork-based rdbSave() (same process) or another forkless
302+
* save. */
300303
char tmpfile[256];
301-
snprintf(tmpfile, sizeof(tmpfile), "temp-%d.rdb", (int)getpid());
304+
snprintf(tmpfile, sizeof(tmpfile), "temp-forkless-%d-%lld.rdb", (int)getpid(), (long long)server.stat_rdb_saves);
302305

303306
FILE *file = fopen(tmpfile, "wb");
304307
if (file == NULL) {

0 commit comments

Comments
 (0)