]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: mux-fcgi: Add a function to propagate termination flags from fstrm to SE
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Feb 2025 13:28:47 +0000 (14:28 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Feb 2025 10:19:32 +0000 (11:19 +0100)
The function fcgi_strm_propagate_term_flags() was added to check the FSTRM
state and evaluate when EOI/EOS/ERR_PENDING/ERROR flags must be set on the
SE. It is not the only place where those flags are set. But it centralizes
the synchro between the FCGI stream and the SC.

For now, this function is only used at the end of fcgi_rcv_buf(). But it
will be used to fix a potential bug.

src/mux_fcgi.c

index 85d30efc7613899adc588ad236d370780fe5f199..bd6efc20e30844a859cadfbcdbb6a74ea1a83c04 100644 (file)
@@ -933,6 +933,26 @@ static inline void fcgi_strm_close(struct fcgi_strm *fstrm)
        }
 }
 
+/* Check fconn and fstrm flags to evaluate if EOI/EOS/ERR_PENDING/ERROR flags must
+ * be set on the SE.
+ */
+static inline void fcgi_strm_propagate_term_flags(struct fcgi_conn *fconn, struct fcgi_strm *fstrm)
+{
+       if (fstrm->h1m.state == H1_MSG_DONE) {
+               se_fl_set(fstrm->sd, SE_FL_EOI);
+               /* Add EOS flag for tunnel */
+               if (!(fstrm->h1m.flags & (H1_MF_VER_11|H1_MF_XFER_LEN)))
+                       se_fl_set(fstrm->sd, SE_FL_EOS);
+       }
+       if (fcgi_conn_read0_pending(fconn) || fstrm->st == FCGI_SS_CLOSED) {
+               se_fl_set(fstrm->sd, SE_FL_EOS);
+               if (!se_fl_test(fstrm->sd, SE_FL_EOI))
+                       se_fl_set(fstrm->sd, SE_FL_ERROR);
+       }
+       if (se_fl_test(fstrm->sd, SE_FL_ERR_PENDING))
+               se_fl_set(strm->sd, SE_FL_ERROR);
+}
+
 /* Detaches a FCGI stream from its FCGI connection and releases it to the
  * fcgi_strm pool.
  */
@@ -3968,18 +3988,7 @@ static size_t fcgi_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count,
        }
        else {
                se_fl_clr(fstrm->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
-               if (fstrm->state == FCGI_SS_ERROR || (fstrm->h1m.state == H1_MSG_DONE)) {
-                       se_fl_set(fstrm->sd, SE_FL_EOI);
-                       if (!(fstrm->h1m.flags & (H1_MF_VER_11|H1_MF_XFER_LEN)))
-                               se_fl_set(fstrm->sd, SE_FL_EOS);
-               }
-               if (fcgi_conn_read0_pending(fconn)) {
-                       se_fl_set(fstrm->sd, SE_FL_EOS);
-                       if (!se_fl_test(fstrm->sd, SE_FL_EOI))
-                               se_fl_set(fstrm->sd, SE_FL_ERROR);
-               }
-               if (se_fl_test(fstrm->sd, SE_FL_ERR_PENDING))
-                       se_fl_set(fstrm->sd, SE_FL_ERROR);
+               fcgi_strm_propagate_term_flags(fconn, fstrm);
                fcgi_release_buf(fconn, &fstrm->rxbuf);
        }