]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream: Use conn-stream to report server error
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 4 Apr 2022 09:06:31 +0000 (11:06 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Apr 2022 13:10:16 +0000 (15:10 +0200)
the stream's srv_error callback function now manipulates a conn-stream
instead of a stream-interface.

include/haproxy/http_ana.h
include/haproxy/stream-t.h
include/haproxy/stream.h
src/backend.c
src/cli.c
src/http_ana.c
src/stream.c

index 73425a64477b51b9bbc81e8357354fcd33f8bffb..a23e55832d046a6bd50d9b43a5e0433b30357bd3 100644 (file)
@@ -50,10 +50,10 @@ int http_res_set_status(unsigned int status, struct ist reason, struct stream *s
 void http_check_request_for_cacheability(struct stream *s, struct channel *req);
 void http_check_response_for_cacheability(struct stream *s, struct channel *res);
 enum rule_result http_wait_for_msg_body(struct stream *s, struct channel *chn, unsigned int time, unsigned int bytes);
-void http_perform_server_redirect(struct stream *s, struct stream_interface *si);
-void http_server_error(struct stream *s, struct stream_interface *si, int err, int finst, struct http_reply *msg);
+void http_perform_server_redirect(struct stream *s, struct conn_stream *cs);
+void http_server_error(struct stream *s, struct conn_stream *cs, int err, int finst, struct http_reply *msg);
 void http_reply_and_close(struct stream *s, short status, struct http_reply *msg);
-void http_return_srv_error(struct stream *s, struct stream_interface *si);
+void http_return_srv_error(struct stream *s, struct conn_stream *cs);
 struct http_reply *http_error_message(struct stream *s);
 int http_reply_to_htx(struct stream *s, struct htx *htx, struct http_reply *reply);
 int http_reply_message(struct stream *s, struct http_reply *reply);
index 075320061329654be1fb30d963d517f57981425e..592fe0b9386afa8de7551bbfa9491b985b704a08 100644 (file)
@@ -195,7 +195,7 @@ struct stream {
 
        void (*do_log)(struct stream *s);       /* the function to call in order to log (or NULL) */
        void (*srv_error)(struct stream *s,     /* the function to call upon unrecoverable server errors (or NULL) */
-                         struct stream_interface *si);
+                         struct conn_stream *cs);
 
        int pcli_next_pid;                      /* next target PID to use for the CLI proxy */
        int pcli_flags;                         /* flags for CLI proxy */
index 32070178a57508f7e06099dbb56df1b4ccd7eecf..b77c9930f24be33506587d9c4c7d1d92fcdaaf2f 100644 (file)
@@ -73,7 +73,7 @@ struct ist stream_generate_unique_id(struct stream *strm, struct list *format);
 void stream_process_counters(struct stream *s);
 void sess_change_server(struct stream *strm, struct server *newsrv);
 struct task *process_stream(struct task *t, void *context, unsigned int state);
-void default_srv_error(struct stream *s, struct stream_interface *si);
+void default_srv_error(struct stream *s, struct conn_stream *cs);
 
 /* Update the stream's backend and server time stats */
 void stream_update_time_stats(struct stream *s);
index 8983e1d0109a328ebf1c46d58124c11fbec2ddf7..3232f0e6174d0a83f2382845a938c4675b37d786 100644 (file)
@@ -1995,7 +1995,7 @@ void back_try_conn_req(struct stream *s)
                        /* no stream was ever accounted for this server */
                        cs->state = CS_ST_CLO;
                        if (s->srv_error)
-                               s->srv_error(s, cs->si);
+                               s->srv_error(s, cs);
                        DBG_TRACE_STATE("internal error during connection", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s);
                        goto end;
                }
@@ -2050,7 +2050,7 @@ void back_try_conn_req(struct stream *s)
                                s->conn_err_type = STRM_ET_QUEUE_TO;
                        cs->state = CS_ST_CLO;
                        if (s->srv_error)
-                               s->srv_error(s, cs->si);
+                               s->srv_error(s, cs);
                        DBG_TRACE_STATE("connection request still queued", STRM_EV_STRM_PROC|STRM_EV_CS_ST, s);
                        goto end;
                }
@@ -2107,7 +2107,7 @@ abort_connection:
        cs_shutw(cs);
        cs->state = CS_ST_CLO;
        if (s->srv_error)
-               s->srv_error(s, cs->si);
+               s->srv_error(s, cs);
        DBG_TRACE_DEVEL("leaving on error", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s);
        return;
 }
@@ -2147,7 +2147,7 @@ void back_handle_st_req(struct stream *s)
                        s->conn_err_type = STRM_ET_CONN_RES;
                        cs->state = CS_ST_CLO;
                        if (s->srv_error)
-                               s->srv_error(s, cs->si);
+                               s->srv_error(s, cs);
                        DBG_TRACE_STATE("failed to register applet", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s);
                        goto end;
                }
@@ -2182,7 +2182,7 @@ void back_handle_st_req(struct stream *s)
                        s->conn_err_type = STRM_ET_CONN_OTHER;
                cs->state = CS_ST_CLO;
                if (s->srv_error)
-                       s->srv_error(s, cs->si);
+                       s->srv_error(s, cs);
                DBG_TRACE_STATE("connection request failed", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s);
                goto end;
        }
@@ -2220,7 +2220,7 @@ void back_handle_st_con(struct stream *s)
                cs_shutw(cs);
                s->conn_err_type |= STRM_ET_CONN_ABRT;
                if (s->srv_error)
-                       s->srv_error(s, cs->si);
+                       s->srv_error(s, cs);
                /* Note: state = CS_ST_DIS now */
                DBG_TRACE_STATE("client abort during connection attempt", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s);
                goto end;
@@ -2319,7 +2319,7 @@ void back_handle_st_cer(struct stream *s)
 
                cs->state = CS_ST_CLO;
                if (s->srv_error)
-                       s->srv_error(s, cs->si);
+                       s->srv_error(s, cs);
 
                DBG_TRACE_STATE("connection failed", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s);
                goto end;
@@ -2353,7 +2353,7 @@ void back_handle_st_cer(struct stream *s)
 
                cs->state = CS_ST_CLO;
                if (s->srv_error)
-                       s->srv_error(s, cs->si);
+                       s->srv_error(s, cs);
 
                DBG_TRACE_STATE("error resetting endpoint", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s);
                goto end;
@@ -2436,7 +2436,7 @@ void back_handle_st_rdy(struct stream *s)
                        cs_shutw(cs);
                        s->conn_err_type |= STRM_ET_CONN_ABRT;
                        if (s->srv_error)
-                               s->srv_error(s, cs->si);
+                               s->srv_error(s, cs);
                        DBG_TRACE_STATE("client abort during connection attempt", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s);
                        goto end;
                }
index 77d8f0a6866c14dab30fdc34adee8280d6dd34ee..ff1610e6ab70e469d60fd9266bf37700910aef26 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2759,7 +2759,7 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                                if (!s->conn_err_type)
                                        s->conn_err_type = STRM_ET_CONN_OTHER;
                                if (s->srv_error)
-                                       s->srv_error(s, cs_si(s->csb));
+                                       s->srv_error(s, s->csb);
                                return 1;
                        }
                }
index 62befbd1df80be191185b76ce7c806e4ac62f273..bf444051cabb26b855ceaaf1b8dab9645e87560e 100644 (file)
@@ -4197,7 +4197,7 @@ enum rule_result http_wait_for_msg_body(struct stream *s, struct channel *chn,
        goto end;
 }
 
-void http_perform_server_redirect(struct stream *s, struct stream_interface *si)
+void http_perform_server_redirect(struct stream *s, struct conn_stream *cs)
 {
        struct channel *req = &s->req;
        struct channel *res = &s->res;
@@ -4260,10 +4260,10 @@ void http_perform_server_redirect(struct stream *s, struct stream_interface *si)
                goto fail;
 
        /* return without error. */
-       cs_shutr(si->cs);
-       cs_shutw(si->cs);
+       cs_shutr(cs);
+       cs_shutw(cs);
        s->conn_err_type = STRM_ET_NONE;
-       si->cs->state = CS_ST_CLO;
+       cs->state = CS_ST_CLO;
 
        if (!(s->flags & SF_ERR_MASK))
                s->flags |= SF_ERR_LOCAL;
@@ -4586,7 +4586,7 @@ int http_forward_proxy_resp(struct stream *s, int final)
        return 1;
 }
 
-void http_server_error(struct stream *s, struct stream_interface *si, int err,
+void http_server_error(struct stream *s, struct conn_stream *cs, int err,
                       int finst, struct http_reply *msg)
 {
        http_reply_and_close(s, s->txn->status, msg);
@@ -4808,50 +4808,50 @@ int http_reply_message(struct stream *s, struct http_reply *reply)
  * Note that connection errors appearing on the second request of a keep-alive
  * connection are not reported since this allows the client to retry.
  */
-void http_return_srv_error(struct stream *s, struct stream_interface *si)
+void http_return_srv_error(struct stream *s, struct conn_stream *cs)
 {
        int err_type = s->conn_err_type;
 
        /* set s->txn->status for http_error_message(s) */
        if (err_type & STRM_ET_QUEUE_ABRT) {
                s->txn->status = -1;
-               http_server_error(s, si, SF_ERR_CLICL, SF_FINST_Q, NULL);
+               http_server_error(s, cs, SF_ERR_CLICL, SF_FINST_Q, NULL);
        }
        else if (err_type & STRM_ET_CONN_ABRT) {
                s->txn->status = -1;
-               http_server_error(s, si, SF_ERR_CLICL, SF_FINST_C, NULL);
+               http_server_error(s, cs, SF_ERR_CLICL, SF_FINST_C, NULL);
        }
        else if (err_type & STRM_ET_QUEUE_TO) {
                s->txn->status = 503;
-               http_server_error(s, si, SF_ERR_SRVTO, SF_FINST_Q,
+               http_server_error(s, cs, SF_ERR_SRVTO, SF_FINST_Q,
                                  http_error_message(s));
        }
        else if (err_type & STRM_ET_QUEUE_ERR) {
                s->txn->status = 503;
-               http_server_error(s, si, SF_ERR_SRVCL, SF_FINST_Q,
+               http_server_error(s, cs, SF_ERR_SRVCL, SF_FINST_Q,
                                  http_error_message(s));
        }
        else if (err_type & STRM_ET_CONN_TO) {
                s->txn->status = 503;
-               http_server_error(s, si, SF_ERR_SRVTO, SF_FINST_C,
+               http_server_error(s, cs, SF_ERR_SRVTO, SF_FINST_C,
                                  (s->txn->flags & TX_NOT_FIRST) ? NULL :
                                  http_error_message(s));
        }
        else if (err_type & STRM_ET_CONN_ERR) {
                s->txn->status = 503;
-               http_server_error(s, si, SF_ERR_SRVCL, SF_FINST_C,
+               http_server_error(s, cs, SF_ERR_SRVCL, SF_FINST_C,
                                  (s->flags & SF_SRV_REUSED) ? NULL :
                                  http_error_message(s));
        }
        else if (err_type & STRM_ET_CONN_RES) {
                s->txn->status = 503;
-               http_server_error(s, si, SF_ERR_RESOURCE, SF_FINST_C,
+               http_server_error(s, cs, SF_ERR_RESOURCE, SF_FINST_C,
                                  (s->txn->flags & TX_NOT_FIRST) ? NULL :
                                  http_error_message(s));
        }
        else { /* STRM_ET_CONN_OTHER and others */
                s->txn->status = 500;
-               http_server_error(s, si, SF_ERR_INTERNAL, SF_FINST_C,
+               http_server_error(s, cs, SF_ERR_INTERNAL, SF_FINST_C,
                                  http_error_message(s));
        }
 }
index e74a4cfbd9564331f5b2fb55495e32867c773c6c..40a79d00f84d6420b53bc9248ecba00b062a31d9 100644 (file)
@@ -2306,7 +2306,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
 
                        srv = objt_server(s->target);
                        if (s->csb->state == CS_ST_ASS && srv && srv->rdr_len && (s->flags & SF_REDIRECTABLE))
-                               http_perform_server_redirect(s, si_b);
+                               http_perform_server_redirect(s, s->csb);
                } while (s->csb->state == CS_ST_ASS);
        }
 
@@ -2686,9 +2686,9 @@ void sess_change_server(struct stream *strm, struct server *newsrv)
 /* Handle server-side errors for default protocols. It is called whenever a a
  * connection setup is aborted or a request is aborted in queue. It sets the
  * stream termination flags so that the caller does not have to worry about
- * them. It's installed as ->srv_error for the server-side stream_interface.
+ * them. It's installed as ->srv_error for the server-side conn_stream.
  */
-void default_srv_error(struct stream *s, struct stream_interface *si)
+void default_srv_error(struct stream *s, struct conn_stream *cs)
 {
        int err_type = s->conn_err_type;
        int err = 0, fin = 0;