Skip to content

[BUG] Potential data race on server.loading flag #7777

@BradSwain

Description

@BradSwain

Describe the bug

We are developing a static data race detection tool and detected a potential data race on the server.loading flag in redis version 6.0.7

To reproduce

If SIGINT is sent while the main thread is inside of loadDataFromDisk, there is a potential data race on the server.loading flag.

The main thread sets the flag while the signal handler may read the flag in parallel.

==== Found a race between: 
line 1996 in rdb.c AND line 4852 in server.c
Shared variable:
 at line 72 of server.c
 72|struct redisServer server; /* Server global state */
Thread 1:
 1994|void startLoading(size_t size, int rdbflags) {
 1995|    /* Load the DB */
>1996|    server.loading = 1;
 1997|    server.loading_start_time = time(NULL);
 1998|    server.loading_loaded_bytes = 0;
>>>Stacktrace:
>>>main
>>>  loadDataFromDisk [server.c:5272]
>>>    loadAppendOnlyFile [server.c:4967]
>>>      startLoadingFile [aof.c:740]
>>>        startLoading [rdb.c:2020]
Thread 2:
 4850|     rdbRemoveTempFile(getpid());
 4851|     exit(1); /* Exit with an error since this was not a clean shutdown. */
>4852| } else if (server.loading) {
 4853|     serverLogFromHandler(LL_WARNING, "Received shutdown signal during loading, exiting now.");
 4854|     exit(0);

>>>Stacktrace:
>>>sigaction [server.c:4869]
>>>  sigShutdownHandler [server.c:4869]

Expected behavior

Should the read/write to server.loading be made atomic?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions