diff --git a/src/cluster.c b/src/cluster.c index 147668a2e3..b434bcc028 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -460,8 +460,8 @@ void clusterSaveConfigOrDie(int do_fsync) { } } -/* Lock the cluster config using flock(), and leaks the file descriptor used to - * acquire the lock so that the file will be locked forever. +/* Lock the cluster config using flock(), and retain the file descriptor used to + * acquire the lock so that the file will be locked as long as the process is up. * * This works because we always update nodes.conf with a new version * in-place, reopening the file, and writing to it in place (later adjusting @@ -500,8 +500,8 @@ int clusterLockConfig(char *filename) { close(fd); return C_ERR; } - /* Lock acquired: leak the 'fd' by not closing it, so that we'll retain the - * lock to the file as long as the process exists. + /* Lock acquired: leak the 'fd' by not closing it until shutdown time, so that + * we'll retain the lock to the file as long as the process exists. * * After fork, the child process will get the fd opened by the parent process, * we need save `fd` to `cluster_config_file_lock_fd`, so that in redisFork(), diff --git a/src/server.c b/src/server.c index 88ace5d3ae..4db60dc6bb 100644 --- a/src/server.c +++ b/src/server.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -4216,6 +4217,12 @@ int finishShutdown(void) { /* Close the listening sockets. Apparently this allows faster restarts. */ closeListeningSockets(1); + + /* Unlock the cluster config file before shutdown */ + if (server.cluster_enabled && server.cluster_config_file_lock_fd != -1) { + flock(server.cluster_config_file_lock_fd, LOCK_UN|LOCK_NB); + } + serverLog(LL_WARNING,"%s is now ready to exit, bye bye...", server.sentinel_mode ? "Sentinel" : "Redis"); return C_OK;