summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2020-06-16 11:45:03 +0200
committerantirez <antirez@gmail.com>2020-06-16 11:45:11 +0200
commit4b8d8826afa0f240b26977e9d128144ebf8d5d7a (patch)
treec060dc19767c97f03a389d25900663267b9f833d
parent62fc7f4f243206d26c3b5246f0887d6cc9925149 (diff)
downloadredis-4b8d8826afa0f240b26977e9d128144ebf8d5d7a.tar.gz
Use cluster connections too, to limit maxclients.
See #7401.
-rw-r--r--src/cluster.c7
-rw-r--r--src/cluster.h1
-rw-r--r--src/networking.c23
3 files changed, 23 insertions, 8 deletions
diff --git a/src/cluster.c b/src/cluster.c
index 24b14d1dc..cacf09bf3 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -691,6 +691,13 @@ void clusterAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
}
}
+/* Return the approximated number of sockets we are using in order to
+ * take the cluster bus connections. */
+unsigned long getClusterConnectionsCount(void) {
+ return server.cluster_enabled ?
+ (dictSize(server.cluster->nodes)*2) : 0;
+}
+
/* -----------------------------------------------------------------------------
* Key space handling
* -------------------------------------------------------------------------- */
diff --git a/src/cluster.h b/src/cluster.h
index d3af4a355..596a4629a 100644
--- a/src/cluster.h
+++ b/src/cluster.h
@@ -283,5 +283,6 @@ typedef struct {
clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, int argc, int *hashslot, int *ask);
int clusterRedirectBlockedClientIfNeeded(client *c);
void clusterRedirectClient(client *c, clusterNode *n, int hashslot, int error_code);
+unsigned long getClusterConnectionsCount(void);
#endif /* __CLUSTER_H */
diff --git a/src/networking.c b/src/networking.c
index 77b9a6fcf..9d36ed3a2 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -892,17 +892,24 @@ static void acceptCommonHandler(connection *conn, int flags, char *ip) {
client *c;
UNUSED(ip);
- /* Admission control will happen before a client is created and connAccept()
+ /* Limit the number of connections we take at the same time.
+ *
+ * Admission control will happen before a client is created and connAccept()
* called, because we don't want to even start transport-level negotiation
- * if rejected.
- */
- if (listLength(server.clients) >= server.maxclients) {
- char *err = "-ERR max number of clients reached\r\n";
+ * if rejected. */
+ if (listLength(server.clients) + getClusterConnectionsCount()
+ >= server.maxclients)
+ {
+ char *err;
+ if (server.cluster_enabled)
+ err = "-ERR max number of clients reached\r\n";
+ else
+ err = "-ERR max number of clients + cluster "
+ "connections reached\r\n";
/* That's a best effort error message, don't check write errors.
- * Note that for TLS connections, no handshake was done yet so nothing is written
- * and the connection will just drop.
- */
+ * Note that for TLS connections, no handshake was done yet so nothing
+ * is written and the connection will just drop. */
if (connWrite(conn,err,strlen(err)) == -1) {
/* Nothing to do, Just to avoid the warning... */
}