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.
This commit is contained in:
Amaury Denoyelle 2023-09-22 15:51:23 +02:00
parent 27b2fd2e06
commit a37abee266
1 changed files with 12 additions and 1 deletions

View File

@ -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;