When h2c_dec_hdrs() fails to allocate the temporary buffer used to
decode the HEADERS frame of a new request, it sets H2_CF_DEM_SALLOC and
the connection is queued in the buffer wait list. But h2_buf_available()
only serves H2_CF_DEM_SALLOC for a stream which has a stream connector,
which is not the case yet, so it never succeeds: the demux remains
blocked and the request is not processed until the connection times
out. This can be reproduced by faking a failed allocation there on the
first request of a connection.
There is no buffer the callback could allocate in this case, so let's
clear the flag and restart the demux, which will retry by itself. Since
b_alloc() refuses to allocate when other entries are queued, the retry
would be queued again and the offered buffer would be lost for
everyone, so a new flag H2_CF_DEM_MAYALLOC is set to let the next
h2_get_buf() allocate with DB_F_NOQUEUE, as mux-h1 does with
H1C_F_IN_MAYALLOC.
This was introduced in 2.0 by commit
5c8cafae3 ("MEDIUM: mux-h2: decode
HEADERS frames before allocating the stream"). It must be backported to
all supported versions. Before 3.0 there is no DB_F_NOQUEUE and the new
flag is not needed, clearing H2_CF_DEM_SALLOC and restarting the demux
is enough.
#define H2_CF_IDL_PING 0x04000000 // timer task scheduled for a PING emission
#define H2_CF_IDL_PING_SENT 0x08000000 // PING emitted, or will be on next tasklet run, waiting for ACK
+#define H2_CF_DEM_MAYALLOC 0x10000000 // demux may allocate its next buffer despite the queue
/* This function is used to report flags in debugging tools. Please reflect
* below any single-bit flag addition above in the same order via the
_(H2_CF_GOAWAY_SENT, _(H2_CF_GOAWAY_FAILED, _(H2_CF_WAIT_FOR_HS, _(H2_CF_IS_BACK,
_(H2_CF_WINDOW_OPENED, _(H2_CF_RCVD_SHUT, _(H2_CF_END_REACHED,
_(H2_CF_RCVD_RFC8441, _(H2_CF_SHTS_UPDATED, _(H2_CF_DTSU_EMITTED,
- _(H2_CF_ERR_PENDING, _(H2_CF_ERROR)))))))))))))))))))))))));
+ _(H2_CF_ERR_PENDING, _(H2_CF_ERROR, _(H2_CF_DEM_MAYALLOC))))))))))))))))))))))))));
/* epilogue */
_(~0U);
return buf;
progress = 1;
}
+ if ((h2c->flags & H2_CF_DEM_SALLOC) &&
+ !h2s_sc(h2c_st_by_id(h2c, h2c->dsi))) {
+ /* no stream to allocate for, let the demux retry */
+ h2c->flags &= ~H2_CF_DEM_SALLOC;
+ h2c->flags |= H2_CF_DEM_MAYALLOC;
+ h2c_restart_reading(h2c, 1);
+ progress = 1;
+ }
+
if ((h2c->flags & H2_CF_DEM_SALLOC) &&
(h2s = h2c_st_by_id(h2c, h2c->dsi)) && h2s_sc(h2s) &&
(h2s_rxbuf_tail(h2s) || h2s_get_rxbuf(h2s))) {
if (b_size(bptr))
return bptr;
- if (likely(!LIST_INLIST(&h2c->buf_wait.list)) &&
- unlikely((buf = b_alloc(bptr, DB_MUX_RX)) == NULL)) {
- b_queue(DB_MUX_RX, &h2c->buf_wait, h2c, h2_buf_available);
+ if (likely(!LIST_INLIST(&h2c->buf_wait.list))) {
+ buf = b_alloc(bptr, DB_MUX_RX |
+ ((h2c->flags & H2_CF_DEM_MAYALLOC) ? DB_F_NOQUEUE : 0));
+ h2c->flags &= ~H2_CF_DEM_MAYALLOC;
+ if (unlikely(!buf))
+ b_queue(DB_MUX_RX, &h2c->buf_wait, h2c, h2_buf_available);
}
return buf;
}