Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -12256,6 +12256,13 @@ int VM_ScanKey(ValkeyModuleKey *key, ValkeyModuleScanCursor *cursor, ValkeyModul
int VM_Fork(ValkeyModuleForkDoneHandler cb, void *user_data) {
pid_t childpid;

/* A module fork must not run concurrently with a background save. */
if (isSaveInProgress()) {
serverLog(LL_WARNING, "Can't fork for module: a background save is in progress");
errno = EALREADY;
return -1;
}

Comment on lines +12259 to +12265

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the better place to do this is within serverFork.

The code in serverFork already checks for certain child types and calls hasActiveChildProcess.

I'd suggest that the best thing would be something like this:

int serverFork(int purpose) {
    if (isMutuallyExclusiveChildType(purpose)) {
        if (hasActiveChildProcess() || bgIteration_iterationActive()) {  // better?
            errno = EALREADY;
            return -1;
        }

        ...

if ((childpid = serverFork(CHILD_TYPE_MODULE)) == 0) {
/* Child */
if (strstr(server.exec_argv[0], "redis-server") != NULL) {
Expand Down
Loading