From a37abee26658e1d1e8e36d8c9e585d2edce3f6d6 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Fri, 22 Sep 2023 15:51:23 +0200 Subject: [PATCH] BUG/MINOR: proto_reverse_connect: set default maxconn If maxconn is not set for preconnect, it assumes we want to establish a single connection. However, this does not work properly in case the connection is closed after reversal. Listener is not resumed by protocol layer to attempt a new preconnect. To fix this, explicitely set maxconn to 1 in the listener instance if none is defined. This ensures the behavior is consistent. A BUG_ON() has been added to validate we never try to use a listener with a 0 maxconn. --- src/proto_reverse_connect.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/proto_reverse_connect.c b/src/proto_reverse_connect.c index f370ce2273..ef8fe21d48 100644 --- a/src/proto_reverse_connect.c +++ b/src/proto_reverse_connect.c @@ -164,6 +164,12 @@ int rev_bind_listener(struct listener *listener, char *errmsg, int errlen) task->context = listener; listener->rx.reverse_connect.task = task; + /* Set a default maxconn to 1. This ensures listener is properly + * reenable each time we fall back below it on connection error. + */ + if (!listener->bind_conf->maxconn) + listener->bind_conf->maxconn = 1; + name = strdup(listener->bind_conf->reverse_srvname); if (!name) { snprintf(errmsg, errlen, "Out of memory."); @@ -229,8 +235,13 @@ struct connection *rev_accept_conn(struct listener *l, int *status) struct connection *conn = l->rx.reverse_connect.pend_conn; if (!conn) { + /* Reverse connect listener must have an explicit maxconn set + * to ensure it is reenabled on connection error. + */ + BUG_ON(!l->bind_conf->maxconn); + /* Instantiate a new conn if maxconn not yet exceeded. */ - if (l->bind_conf->maxconn && l->nbconn <= l->bind_conf->maxconn) { + if (l->nbconn <= l->bind_conf->maxconn) { l->rx.reverse_connect.pend_conn = new_reverse_conn(l, l->rx.reverse_connect.srv); if (!l->rx.reverse_connect.pend_conn) { *status = CO_AC_PAUSE;