Hi Willy,

Le 09/09/2014 08:08, Willy Tarreau a écrit :
Hi Cyril,

On Sun, Sep 07, 2014 at 06:30:40PM +0200, Cyril Bonté wrote:
I was optimistic during my tests unless I tried sending POST requests
with a body longer than the buffer size. In certain conditions, haproxy
segfaults. For example, this is the case with the "bad" server, no need
to redispatch.

I need some time to remember how buffers work in 1.4, in order to fix
the segfault.

Argh, crap! I fear that we're opening a new can of worms :-(

At least we have working code in 1.5 so we know there's a fix, but the two
versions are so much different that we cannot port 1.5 changes back to 1.4.
It's possible however that we'll have to add a WAIT_CONN flag to prevent
the body from being parsed/forwarded until the connection is opened.

It is quite ugly but I wonder if the patch attached could be a solution.
The idea is to reduce the max buffer length to (buf->size - maxrewrite) when http-send-name-header is used, until the connection to the server is established.

--
Cyril Bonté
diff --git a/include/proto/buffers.h b/include/proto/buffers.h
index 5d1372a..58aff54 100644
--- a/include/proto/buffers.h
+++ b/include/proto/buffers.h
@@ -59,7 +59,9 @@ static inline void buffer_init(struct buffer *buf)
  */
 static inline int buffer_max_len(struct buffer *buf)
 {
-	if (buf->to_forward == BUF_INFINITE_FORWARD ||
+	if (buf->flags & BF_WAIT_CONN)
+		return buf->size - global.tune.maxrewrite;
+	else if (buf->to_forward == BUF_INFINITE_FORWARD ||
 	    buf->to_forward + buf->send_max >= global.tune.maxrewrite)
 		return buf->size;
 	else
diff --git a/include/types/buffers.h b/include/types/buffers.h
index 474cdb3..f05e3d6 100644
--- a/include/types/buffers.h
+++ b/include/types/buffers.h
@@ -113,9 +113,11 @@
 
 #define BF_DONT_READ     0x1000000  /* disable reading for now */
 #define BF_EXPECT_MORE   0x2000000  /* more data expected to be sent very soon (one-shoot) */
-#define BF_SEND_DONTWAIT 0x4000000  /* don't wait for sending data (one-shoot) */
+#define BF_SEND_DONTWAIT 0x4000000  /* don't wait for sending data (one-shot) */
 #define BF_NEVER_WAIT    0x8000000  /* never wait for sending data (permanent) */
 
+#define BF_WAIT_CONN    0x10000000  /* wait to be connected to the server before extending the buffer size */
+
 /* Use these masks to clear the flags before going back to lower layers */
 #define BF_CLEAR_READ     (~(BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR|BF_READ_ATTACHED))
 #define BF_CLEAR_WRITE    (~(BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_WRITE_ERROR))
diff --git a/src/proto_http.c b/src/proto_http.c
index 7c156ed..f4634f2 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -4076,6 +4076,7 @@ int http_send_name_header(struct http_txn *txn, struct http_msg *msg, struct buf
 
 	/* Adjust buffer data length to send */
 	buf->send_max -= delta;
+	txn->req.som -= delta;
 
 	return 0;
 }
diff --git a/src/session.c b/src/session.c
index 387fcc1..aa42acb 100644
--- a/src/session.c
+++ b/src/session.c
@@ -342,6 +342,7 @@ void sess_establish(struct session *s, struct stream_interface *si)
 	}
 	else {
 		s->txn.rsp.msg_state = HTTP_MSG_RPBEFORE;
+		s->req->flags &= ~BF_WAIT_CONN;
 		/* reset hdr_idx which was already initialized by the request.
 		 * right now, the http parser does it.
 		 * hdr_idx_init(&s->txn.hdr_idx);
@@ -1404,6 +1405,10 @@ resync_stream_interface:
 	 */
 	if (s->req->cons->state == SI_ST_INI) {
 		if (!(s->req->flags & BF_SHUTW)) {
+			if ((s->be->mode == PR_MODE_HTTP) &&
+			    (s->be->server_id_hdr_name != NULL))
+				s->req->flags |= BF_WAIT_CONN;
+
 			if ((s->req->flags & (BF_AUTO_CONNECT|BF_OUT_EMPTY)) != BF_OUT_EMPTY) {
 				/* If we have a ->connect method, we need to perform a connection request,
 				 * otherwise we immediately switch to the connected state.

Reply via email to