From: Christopher Faulet Date: Wed, 5 Feb 2025 13:28:47 +0000 (+0100) Subject: MEDIUM: mux-fcgi: Add a function to propagate termination flags from fstrm to SE X-Git-Tag: v3.2-dev5~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ccdca4bb77f49b031ebf356c1d706fd43677799b;p=thirdparty%2Fhaproxy.git MEDIUM: mux-fcgi: Add a function to propagate termination flags from fstrm to SE 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. --- diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 85d30efc7..bd6efc20e 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -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); }