From b7209d42d95c1e25774d094803db33a028b68179 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 23 May 2023 16:08:22 +0200 Subject: [PATCH] MEDIUM: stconn: make the SE_FL_ERR_PENDING to ERROR transition systematic During a code audit of the various situations that promote ERR_PENDING to ERROR, it appeared that: - all muxes use se_fl_set_error() to set it, which chooses either based on EOI/EOS presence ; - EOI/EOS that arrive late after ERR_PENDING were not systematically upgraded to ERROR This results in confusion about how such ERROR or ERR_PENDING ought to be handled, which is not quite desirable. This patch adds a test to se_fl_set() to detect if we're setting EOI or EOS while ERR_PENDING is present, or the other way around so that any sequence of EOI/EOS <-> ERR_PENDING results in ERROR being set. This way there will no longer be possible situations where ERROR is missing while the other ones are set. --- include/haproxy/stconn.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/haproxy/stconn.h b/include/haproxy/stconn.h index 97460c7c5..8d9ac6650 100644 --- a/include/haproxy/stconn.h +++ b/include/haproxy/stconn.h @@ -77,8 +77,14 @@ static forceinline void se_fl_setall(struct sedesc *se, uint all) se->flags = all; } +/* sets flags on se->flags and handles ERR_PENDING to ERROR promotion if + * needed (upon EOI/EOS). + */ static forceinline void se_fl_set(struct sedesc *se, uint on) { + if (((on & (SE_FL_EOS|SE_FL_EOI)) && se->flags & SE_FL_ERR_PENDING) || + ((on & SE_FL_ERR_PENDING) && se->flags & (SE_FL_EOI|SE_FL_EOS))) + on |= SE_FL_ERROR; se->flags |= on; }