From: Olivier Houchard Date: Fri, 23 Nov 2018 16:07:04 +0000 (+0100) Subject: MEDIUM: servers: Store the connection in the SI until we have a mux. X-Git-Tag: v1.9-dev8~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee23b2a1e34ceb0b5c2b608b8d48d5a826d6f63e;p=thirdparty%2Fhaproxy.git MEDIUM: servers: Store the connection in the SI until we have a mux. When we create a connection, if we have to defer the conn_stream and the mux creation until we can decide it (ie until the SSL handshake is done, and the ALPN is decided), store the connection in the stream_interface, so that we're sure we can destroy it if needed. --- diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index 5568fdb682..a091439e42 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -161,6 +161,7 @@ static inline enum obj_type *si_detach_endpoint(struct stream_interface *si) */ static inline void si_release_endpoint(struct stream_interface *si) { + struct connection *conn; struct conn_stream *cs; struct appctx *appctx; @@ -177,7 +178,8 @@ static inline void si_release_endpoint(struct stream_interface *si) if (appctx->applet->release && si->state < SI_ST_DIS) appctx->applet->release(appctx); appctx_free(appctx); /* we share the connection pool */ - } + } else if ((conn = objt_conn(si->end))) + conn_free(conn); si_detach_endpoint(si); } diff --git a/src/backend.c b/src/backend.c index 3ab450bcb1..cdc63c6ad6 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1279,9 +1279,10 @@ int connect_server(struct stream *s) /* Store the connection into the stream interface, * while we still don't have a mux, so that if the * stream is destroyed before the connection is - * established, and a mux is set, we don't attempt - * to access the stream + * established, we have a chance to destroy it even + * if it is no longer referenced in the session. */ + s->si[1].end = &srv_conn->obj_type; conn_set_xprt_done_cb(srv_conn, conn_complete_server); }