]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stream: allocate the session when a stream is created
authorWilly Tarreau <w@1wt.eu>
Fri, 3 Apr 2015 12:10:06 +0000 (14:10 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 Apr 2015 09:23:57 +0000 (11:23 +0200)
This is where we'll put some session-wide information.

src/haproxy.c
src/hlua.c
src/peers.c
src/stream.c

index 591bb96e6cdd79952b82b11b02c376e4c0ef690e..4510375d361ff50a7ef4f5e49dcef93f88bb59f0 100644 (file)
@@ -1433,6 +1433,7 @@ void deinit(void)
        }
 
        pool_destroy2(pool2_stream);
+       pool_destroy2(pool2_session);
        pool_destroy2(pool2_connection);
        pool_destroy2(pool2_buffer);
        pool_destroy2(pool2_requri);
index cdbce004303e82ee506a98b30a66955a54468310..4b56187d437764db30f638f852b41f564a367d9c 100644 (file)
@@ -31,6 +31,7 @@
 #include <proto/raw_sock.h>
 #include <proto/sample.h>
 #include <proto/server.h>
+#include <proto/session.h>
 #include <proto/stream.h>
 #include <proto/ssl_sock.h>
 #include <proto/stream_interface.h>
@@ -2025,17 +2026,22 @@ __LJMP static int hlua_socket_new(lua_State *L)
         * Get memory for the request.
         *
         */
+       socket->s->sess = pool_alloc2(pool2_session);
+       if (!socket->s->sess) {
+               hlua_pusherror(L, "socket: out of memory");
+               goto out_fail_conf;
+       }
 
        socket->s = pool_alloc2(pool2_stream);
        if (!socket->s) {
                hlua_pusherror(L, "socket: out of memory");
-               goto out_fail_conf;
+               goto out_fail_stream;
        }
 
        socket->s->task = task_new();
        if (!socket->s->task) {
                hlua_pusherror(L, "socket: out of memory");
-               goto out_free_session;
+               goto out_fail_task;
        }
 
        socket->s->req.buf = pool_alloc2(pool2_buffer);
@@ -2127,7 +2133,6 @@ __LJMP static int hlua_socket_new(lua_State *L)
        /* The stream dont have listener. The listener is used with real
         * proxies.
         */
-       socket->s->sess = NULL;
        socket->s->listener = NULL;
 
        /* The flags are initialized to 0. Values are setted later. */
@@ -2228,8 +2233,10 @@ out_fail_rep_buf:
        pool_free2(pool2_buffer, socket->s->req.buf);
 out_fail_req_buf:
        task_free(socket->s->task);
-out_free_session:
+out_fail_task:
        pool_free2(pool2_stream, socket->s);
+out_fail_stream:
+       pool_free2(pool2_session, socket->s->sess);
 out_fail_conf:
        WILL_LJMP(lua_error(L));
        return 0;
index 0a66010dc11a7b9208c05585b59a0c5e17027505..28013203c835d94f6a2cee9b288ea7a5bf7e9ac2 100644 (file)
@@ -38,6 +38,7 @@
 #include <proto/proto_tcp.h>
 #include <proto/proto_http.h>
 #include <proto/proxy.h>
+#include <proto/session.h>
 #include <proto/stream.h>
 #include <proto/signal.h>
 #include <proto/stick_table.h>
@@ -1132,7 +1133,7 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session
         */
        if ((t = task_new()) == NULL) { /* disable this proxy for a while */
                Alert("out of memory in peer_session_create().\n");
-               goto out_free_session;
+               goto out_free_stream;
        }
 
        ps->reconnect = tick_add(now_ms, MS_TO_TICKS(5000));
@@ -1144,7 +1145,11 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session
 
        s->task = t;
        s->listener = l;
-       s->sess = NULL;
+       s->sess = pool_alloc2(pool2_session);
+       if (!s->sess) {
+               Alert("out of memory in peer_session_create().\n");
+               goto out_free_task;
+       }
 
        /* Note: initially, the stream's backend points to the frontend.
         * This changes later when switching rules are executed or
@@ -1275,8 +1280,10 @@ static struct stream *peer_session_create(struct peer *peer, struct peer_session
 
        /* Error unrolling */
  out_fail_conn1:
+       pool_free2(pool2_session, s->sess);
+ out_free_task:
        task_free(t);
- out_free_session:
+ out_free_stream:
        LIST_DEL(&s->list);
        pool_free2(pool2_stream, s);
  out_close:
index aaea9c08c8159d8b0b7336e5ec50de936289f2cc..e81de2ad01821792a41d981eb20a846086328a67 100644 (file)
@@ -37,6 +37,7 @@
 #include <proto/listener.h>
 #include <proto/log.h>
 #include <proto/raw_sock.h>
+#include <proto/session.h>
 #include <proto/stream.h>
 #include <proto/pipe.h>
 #include <proto/proto_http.h>
@@ -116,7 +117,10 @@ int stream_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
 
        memset(s->stkctr, 0, sizeof(s->stkctr));
 
-       s->sess = NULL;
+       s->sess = pool_alloc2(pool2_session);
+       if (!s->sess)
+               goto out_free_stream;
+
        s->listener = l;
        s->fe  = p;
 
@@ -235,6 +239,8 @@ int stream_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
  out_free_task:
        task_free(t);
  out_free_session:
+       pool_free2(pool2_session, s->sess);
+ out_free_stream:
        p->feconn--;
        stream_store_counters(s);
        pool_free2(pool2_stream, s);
@@ -352,6 +358,10 @@ static void kill_mini_session(struct stream *s)
 
        task_delete(s->task);
        task_free(s->task);
+       /* FIXME: for now we have a 1:1 relation between stream and session so
+        * the stream must free the session.
+        */
+       pool_free2(pool2_session, s->sess);
        pool_free2(pool2_stream, s);
 }
 
@@ -655,6 +665,11 @@ static void stream_free(struct stream *s)
        LIST_DEL(&s->list);
        si_release_endpoint(&s->si[1]);
        si_release_endpoint(&s->si[0]);
+
+       /* FIXME: for now we have a 1:1 relation between stream and session so
+        * the stream must free the session.
+        */
+       pool_free2(pool2_session, s->sess);
        pool_free2(pool2_stream, s);
 
        /* We may want to free the maximum amount of pools if the proxy is stopping */
@@ -664,6 +679,7 @@ static void stream_free(struct stream *s)
                pool_flush2(pool2_requri);
                pool_flush2(pool2_capture);
                pool_flush2(pool2_stream);
+               pool_flush2(pool2_session);
                pool_flush2(pool2_connection);
                pool_flush2(pool2_pendconn);
                pool_flush2(fe->req_cap_pool);