diff --git a/include/haproxy/tinfo-t.h b/include/haproxy/tinfo-t.h index fc8514305d..357c4c0aae 100644 --- a/include/haproxy/tinfo-t.h +++ b/include/haproxy/tinfo-t.h @@ -141,6 +141,7 @@ struct thread_ctx { struct list quic_conns; /* list of active quic-conns attached to this thread */ struct list quic_conns_clo; /* list of closing quic-conns attached to this thread */ struct list queued_checks; /* checks waiting for a connection slot */ + unsigned int nb_rhttp_conns; /* count of current conns used for active reverse HTTP */ ALWAYS_ALIGN(2*sizeof(void*)); struct list tasklets[TL_CLASSES]; /* tasklets (and/or tasks) to run, by class */ diff --git a/src/connection.c b/src/connection.c index 340fa4f22a..7930cc41c3 100644 --- a/src/connection.c +++ b/src/connection.c @@ -592,7 +592,12 @@ void conn_free(struct connection *conn) if (conn_reverse_in_preconnect(conn)) { struct listener *l = conn_active_reverse_listener(conn); rhttp_notify_preconn_err(l); + HA_ATOMIC_DEC(&th_ctx->nb_rhttp_conns); } + else if (conn->flags & CO_FL_REVERSED) { + HA_ATOMIC_DEC(&th_ctx->nb_rhttp_conns); + } + conn_force_unsubscribe(conn); pool_free(pool_head_connection, conn); diff --git a/src/proto_rhttp.c b/src/proto_rhttp.c index a60caa7d6e..52d45441fe 100644 --- a/src/proto_rhttp.c +++ b/src/proto_rhttp.c @@ -56,6 +56,8 @@ static struct connection *new_reverse_conn(struct listener *l, struct server *sr if (!conn) goto err; + HA_ATOMIC_INC(&th_ctx->nb_rhttp_conns); + conn_set_reverse(conn, &l->obj_type); if (alloc_bind_address(&bind_addr, srv, srv->proxy, NULL) != SRV_STATUS_OK) @@ -376,3 +378,14 @@ int rhttp_accepting_conn(const struct receiver *rx) } INITCALL1(STG_REGISTER, protocol_register, &proto_rhttp); + +/* perform minimal intializations */ +static void init_rhttp() +{ + int i; + + for (i = 0; i < MAX_THREADS; i++) + ha_thread_ctx[i].nb_rhttp_conns = 0; +} + +INITCALL0(STG_PREPARE, init_rhttp);