]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Let the frontend appctx release the session
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 11 May 2022 10:22:10 +0000 (12:22 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 May 2022 14:13:21 +0000 (16:13 +0200)
The session created for frontend applets is now totally owns by the
corresponding appctx. It means the appctx is now responsible to release
it. This removes the hack in stream_free() about frontend applets to be sure
to release the session.

src/dns.c
src/flt_spoe.c
src/hlua.c
src/http_client.c
src/peers.c
src/sink.c
src/stream.c

index bfd22c1b9e2b9f789c363d7e806d5dc99a0ab34f..716514b04805bfb41266e180e503fa5a087c7f23 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -934,9 +934,10 @@ static struct appctx *dns_session_create(struct dns_session *ds)
                ha_alert("out of memory in dns_session_create().\n");
                goto out_free_appctx;
        }
+       appctx->sess = sess;
 
        if (!sockaddr_alloc(&addr, &ds->dss->srv->addr, sizeof(ds->dss->srv->addr)))
-               goto out_free_sess;
+               goto out_free_appctx;
 
        cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs) {
@@ -965,8 +966,6 @@ static struct appctx *dns_session_create(struct dns_session *ds)
        /* Error unrolling */
  out_free_addr:
        sockaddr_free(&addr);
- out_free_sess:
-       session_free(sess);
  out_free_appctx:
        appctx_free(appctx);
  out_close:
index 030ba9c8af061e5c8997a4bfebff7d42264d0b56..c176a9b411c3650bee8eab4d19892cab0d488565 100644 (file)
@@ -2026,9 +2026,10 @@ spoe_create_appctx(struct spoe_config *conf)
        if (!sess)
                goto out_free_spoe;
 
+       appctx->sess = sess;
        cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs)
-               goto out_free_sess;
+               goto out_free_spoe;
 
        strm = DISGUISE(cs_strm(cs));
        stream_set_backend(strm, conf->agent->b.be);
@@ -2049,8 +2050,6 @@ spoe_create_appctx(struct spoe_config *conf)
        return appctx;
 
        /* Error unrolling */
- out_free_sess:
-       session_free(sess);
  out_free_spoe:
        task_destroy(SPOE_APPCTX(appctx)->task);
  out_free_spoe_appctx:
index abe3556b6e6e888588e78d70091685bd364f7bfa..193956a91a71e12cf4b9d4552c3a4a09e2021c66 100644 (file)
@@ -2994,10 +2994,11 @@ __LJMP static int hlua_socket_new(lua_State *L)
                goto out_fail_appctx;
        }
 
+       appctx->sess = sess;
        cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs) {
                hlua_pusherror(L, "socket: out of memory");
-               goto out_fail_sess;
+               goto out_fail_appctx;
        }
 
        s = DISGUISE(cs_strm(cs));
@@ -3017,8 +3018,6 @@ __LJMP static int hlua_socket_new(lua_State *L)
 
        return 1;
 
- out_fail_sess:
-       session_free(sess);
  out_fail_appctx:
        appctx_free(appctx);
  out_fail_conf:
index 4daacea1da1e8e18383cd606753c7124434b6a7d..b818396f821f9ce8ad876b1b66675f788ec8e28a 100644 (file)
@@ -578,6 +578,7 @@ struct appctx *httpclient_start(struct httpclient *hc)
                ha_alert("httpclient: out of memory in %s:%d.\n", __FUNCTION__, __LINE__);
                goto out_free_appctx;
        }
+       appctx->sess = sess;
 
        /* choose the SSL server or not */
        switch (scheme) {
@@ -590,22 +591,22 @@ struct appctx *httpclient_start(struct httpclient *hc)
                                target = &httpclient_srv_ssl->obj_type;
                        } else {
                                ha_alert("httpclient: SSL was disabled (wrong verify/ca-file)!\n");
-                               goto out_free_sess;
+                               goto out_free_appctx;
                        }
 #else
                        ha_alert("httpclient: OpenSSL is not available %s:%d.\n", __FUNCTION__, __LINE__);
-                       goto out_free_sess;
+                       goto out_free_appctx;
 #endif
                        break;
        }
 
        if (!ss_dst) {
                ha_alert("httpclient: Failed to initialize address %s:%d.\n", __FUNCTION__, __LINE__);
-               goto out_free_sess;
+               goto out_free_appctx;
        }
 
        if (!sockaddr_alloc(&addr, ss_dst, sizeof(*ss_dst)))
-               goto out_free_sess;
+               goto out_free_appctx;
 
        cs = cs_new_from_endp(appctx->endp, sess, &hc->req.buf);
        if (!cs) {
@@ -650,8 +651,6 @@ struct appctx *httpclient_start(struct httpclient *hc)
 
 out_free_addr:
        sockaddr_free(&addr);
-out_free_sess:
-       session_free(sess);
 out_free_appctx:
        appctx_free(appctx);
 out:
index 58f771b97df208b510872d4900ef1b2107c88ced..07520a4b42f2f53e81c49300208a08f5a75538bc 100644 (file)
@@ -3190,14 +3190,15 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
                ha_alert("out of memory in peer_session_create().\n");
                goto out_free_appctx;
        }
+       appctx->sess = sess;
 
        if (!sockaddr_alloc(&addr, &peer->addr, sizeof(peer->addr)))
-               goto out_free_sess;
+               goto out_free_appctx;
 
        cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs) {
                ha_alert("Failed to initialize stream in peer_session_create().\n");
-               goto out_free_addr;
+               goto out_free_appctx;
        }
 
        s = DISGUISE(cs_strm(cs));
@@ -3224,8 +3225,6 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
        /* Error unrolling */
  out_free_addr:
        sockaddr_free(&addr);
- out_free_sess:
-       session_free(sess);
  out_free_appctx:
        appctx_free(appctx);
  out_close:
index c52afc68dcae10ef4c2c8da3cf7f44d72deec214..59391859ee107a0f0968a9fa4fa6bcaa95eeb6b8 100644 (file)
@@ -650,14 +650,15 @@ static struct appctx *sink_forward_session_create(struct sink *sink, struct sink
                ha_alert("out of memory in sink_forward_session_create().\n");
                goto out_free_appctx;
        }
+       appctx->sess = sess;
 
        if (!sockaddr_alloc(&addr, &sft->srv->addr, sizeof(sft->srv->addr)))
-               goto out_free_sess;
+               goto out_free_appctx;
 
        cs = cs_new_from_endp(appctx->endp, sess, &BUF_NULL);
        if (!cs) {
                ha_alert("Failed to initialize stream in sink_forward_session_create().\n");
-               goto out_free_addr;
+               goto out_free_appctx;
        }
        s = DISGUISE(cs_strm(cs));
 
@@ -682,8 +683,6 @@ static struct appctx *sink_forward_session_create(struct sink *sink, struct sink
        /* Error unrolling */
  out_free_addr:
        sockaddr_free(&addr);
- out_free_sess:
-       session_free(sess);
  out_free_appctx:
        appctx_free(appctx);
  out_close:
index c7002366ff9903c14f1e26827d84a458fdab6074..00abce656e95f6fda681f4acdcf18c53ae287e7e 100644 (file)
@@ -585,7 +585,6 @@ static void stream_free(struct stream *s)
        struct session *sess = strm_sess(s);
        struct proxy *fe = sess->fe;
        struct bref *bref, *back;
-       int must_free_sess;
        int i;
 
        DBG_TRACE_POINT(STRM_EV_STRM_FREE, s);
@@ -709,18 +708,9 @@ static void stream_free(struct stream *s)
        }
        LIST_DELETE(&s->list);
 
-       /* applets do not release session yet */
-       /* FIXME: Handle it in appctx_free ??? */
-       must_free_sess = objt_appctx(sess->origin) && sess->origin == __cs_endp_target(s->csf);
-
        cs_destroy(s->csb);
        cs_destroy(s->csf);
 
-       if (must_free_sess) {
-               sess->origin = NULL;
-               session_free(sess);
-       }
-
        pool_free(pool_head_stream, s);
 
        /* We may want to free the maximum amount of pools if the proxy is stopping */