diff --git a/src/server.c b/src/server.c index 42b6198d9..911441d56 100644 --- a/src/server.c +++ b/src/server.c @@ -5937,8 +5937,10 @@ void closeChildUnusedResourceAfterFork() { /* purpose is one of CHILD_TYPE_ types */ int redisFork(int purpose) { if (isMutuallyExclusiveChildType(purpose)) { - if (hasActiveChildProcess()) + if (hasActiveChildProcess()) { + errno = EEXIST; return -1; + } openChildInfoPipe(); } diff --git a/tests/unit/moduleapi/fork.tcl b/tests/unit/moduleapi/fork.tcl index a6a9b8a1e..64184d01e 100644 --- a/tests/unit/moduleapi/fork.tcl +++ b/tests/unit/moduleapi/fork.tcl @@ -32,4 +32,11 @@ start_server {tags {"modules"}} { assert {[count_log_message "fork child exiting"] eq "1"} } + test {Module fork twice} { + r fork.create 0 + after 250 + catch {r fork.create 0} + assert {[count_log_message "Can't fork for module: File exists"] eq "1"} + } + }