]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stconn: Be sure to always be able to unblock a SC that needs room
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 9 May 2023 09:44:56 +0000 (11:44 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 9 May 2023 09:53:28 +0000 (11:53 +0200)
When sc_need_room() is called, the caller cannot request more free space
than a minimum value to be sure it is always possible to unblock it. it is a
safety guard to not freeze any SC on NEED_ROOM condition. At worse it will
lead to some wakeups un excess at the edge.

To keep things simple, the following minimum is used:

  (global.tune.bufsize - global.tune.maxrewrite - sizeof(struct htx))

include/haproxy/stconn.h

index acc22977b9295cb9b69a1e32e80095a08d6d0e04..97460c7c5d3f05ccc4dd016cea6baf5b6ee998a0 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <haproxy/api.h>
 #include <haproxy/connection.h>
+#include <haproxy/htx-t.h>
 #include <haproxy/obj_type.h>
 #include <haproxy/stconn-t.h>
 
@@ -444,12 +445,13 @@ static inline void sc_have_room(struct stconn *sc)
  * SE_FL_HAVE_NO_DATA to be called again as soon as SC_FL_NEED_ROOM is cleared.
  *
  * The caller is responsible to specified the amount of free space required to
- * progress.
+ * progress. However, to be sure the SC can be unblocked a max value cannot be
+ * eceeded : (BUFSIZE - RESERVE - HTX OVERHEAD)
  */
 static inline void sc_need_room(struct stconn *sc, ssize_t room_needed)
 {
        sc->flags |= SC_FL_NEED_ROOM;
-       sc->room_needed = room_needed;
+       sc->room_needed = MIN(global.tune.bufsize - global.tune.maxrewrite - sizeof(struct htx), room_needed);
 }
 
 /* The stream endpoint indicates that it's ready to consume data from the