674d5bbfcde5dfed81c1f9e7b58e6226bb2c7272
[feed/packages.git] /
1 commit 620381599324e15403002270637a3b677c3fe7e5
2 Author: Willy Tarreau <w@1wt.eu>
3 Date: Fri Aug 23 09:29:29 2019 +0200
4
5 BUG/MEDIUM: mux-h1: do not report errors on transfers ending on buffer full
6
7 If a receipt ends with the HTX buffer full and everything is completed except
8 appending the HTX EOM block, we end up detecting an error because the H1
9 parser did not switch to H1_MSG_DONE yet while all conditions for an end of
10 stream and end of buffer are met. This can be detected by retrieving 31532
11 or 31533 chunk-encoded bytes over H1 and seeing haproxy log "SD--" at the
12 end of a successful transfer.
13
14 Ideally the EOM part should be totally independent on the H1 message state
15 since the block was really parsed and finished. So we should switch to a
16 last state requiring to send only EOM. However this needs a few risky
17 changes. This patch aims for simplicity and backport safety, thus it only
18 adds a flag to the H1 stream indicating that an EOM is still needed, and
19 excludes this condition from the ones used to detect end of processing. A
20 cleaner approach needs to be studied, either by adding a state before DONE
21 or by setting DONE once the various blocks are parsed and before trying to
22 send EOM.
23
24 This fix must be backported to 2.0. The issue does not seem to affect 1.9
25 though it is not yet known why, probably that it is related to the different
26 encoding of trailers which always leaves a bit of room to let EOM be stored.
27
28 (cherry picked from commit 0bb5a5c4b5ad375b1254c2e8bec2dd5ea85d6ebb)
29 Signed-off-by: Willy Tarreau <w@1wt.eu>
30
31 diff --git a/src/mux_h1.c b/src/mux_h1.c
32 index 01f225a2..b9a37ce5 100644
33 --- a/src/mux_h1.c
34 +++ b/src/mux_h1.c
35 @@ -67,7 +67,8 @@
36 #define H1S_F_BUF_FLUSH 0x00000100 /* Flush input buffer and don't read more data */
37 #define H1S_F_SPLICED_DATA 0x00000200 /* Set when the kernel splicing is in used */
38 #define H1S_F_HAVE_I_TLR 0x00000800 /* Set during input process to know the trailers were processed */
39 -/* 0x00001000 .. 0x00002000 unused */
40 +#define H1S_F_APPEND_EOM 0x00001000 /* Send EOM to the HTX buffer */
41 +/* 0x00002000 .. 0x00002000 unused */
42 #define H1S_F_HAVE_O_CONN 0x00004000 /* Set during output process to know connection mode was processed */
43
44 /* H1 connection descriptor */
45 @@ -954,9 +955,12 @@ static size_t h1_eval_htx_res_size(struct h1m *h1m, union h1_sl *h1sl, struct ht
46 */
47 static size_t h1_process_eom(struct h1s *h1s, struct h1m *h1m, struct htx *htx, size_t max)
48 {
49 - if (max < sizeof(struct htx_blk) + 1 || !htx_add_endof(htx, HTX_BLK_EOM))
50 + if (max < sizeof(struct htx_blk) + 1 || !htx_add_endof(htx, HTX_BLK_EOM)) {
51 + h1s->flags |= H1S_F_APPEND_EOM;
52 return 0;
53 + }
54
55 + h1s->flags &= ~H1S_F_APPEND_EOM;
56 h1m->state = H1_MSG_DONE;
57 h1s->cs->flags |= CS_FL_EOI;
58 return (sizeof(struct htx_blk) + 1);
59 @@ -1472,7 +1476,8 @@ static size_t h1_process_input(struct h1c *h1c, struct buffer *buf, size_t count
60 else if (h1s_data_pending(h1s) && !htx_is_empty(htx))
61 h1s->cs->flags |= CS_FL_RCV_MORE | CS_FL_WANT_ROOM;
62
63 - if ((h1s->flags & H1S_F_REOS) && (!h1s_data_pending(h1s) || htx_is_empty(htx))) {
64 + if (((h1s->flags & (H1S_F_REOS|H1S_F_APPEND_EOM)) == H1S_F_REOS) &&
65 + (!h1s_data_pending(h1s) || htx_is_empty(htx))) {
66 h1s->cs->flags |= CS_FL_EOS;
67 if (h1m->state > H1_MSG_LAST_LF && h1m->state < H1_MSG_DONE)
68 h1s->cs->flags |= CS_FL_ERROR;