Hi,

While testing QMux, I found that a client which does not read the
response until the socket buffer is full crashes haproxy, as
qcc_qmux_send_frames() does not support partial writes.

I gave a try at a fix: the first patch keeps the unsent part of the
record in the Tx buffer and retries later, the second one keeps the
connection open until this data is flushed so that the end of the
response is not lost. I am well aware this may not be the right
approach, so any feedback is welcome and I will adapt the patches as
needed.

Reproducer, with any HTTP server on 127.0.0.1:8000 serving a 4MB file
as /big.

haproxy.cfg:

    global
        expose-experimental-directives
    defaults
        mode http
        timeout client 30s
        timeout server 30s
        timeout connect 5s
    frontend fe
        bind :8443 proto qmux
        default_backend be
    backend be
        server s1 127.0.0.1:8000

repro.py:

    import socket, sys, time

    def vi(v):  # QUIC varint
        for n, p in ((1, 0), (2, 0x4000), (4, 0x80000000), (8, 
0xC000000000000000)):
            if v < 1 << (8 * n - 2):
                return (v | p).to_bytes(n, "big")

    def rec(b):  # QMux record
        return vi(len(b)) + b

    tp = b"".join(vi(i) + vi(len(vi(v))) + vi(v)
                  for i, v in ((4, 1 << 40), (5, 1 << 40), (6, 1 << 40),
                               (7, 1 << 40), (8, 100), (9, 100)))
    qpack = b"\x00\x00\xd1\xd6\x50\x01x\x51\x04/big"  # GET http://x/big
    hdrs = vi(1) + vi(len(qpack)) + qpack
    s = socket.create_connection((sys.argv[1], int(sys.argv[2])))
    s.sendall(rec(vi(0x3F5153300D0A0D0A) + vi(len(tp)) + tp) +
              rec(vi(0x0b) + vi(0) + vi(len(hdrs)) + hdrs))
    time.sleep(5)  # never read the response

$ python3 repro.py 127.0.0.1 8443
FATAL: bug condition "sent != b_data(buf)" matched at src/qcm_qmux.c:385

Both patches should be backported to 3.4.

William

William Dauchy (2):
  BUG/MEDIUM: qmux: retry on partial write instead of aborting
  BUG/MINOR: qmux: do not release connection with pending Tx record data

 include/haproxy/qcm_qmux.h |  9 ++++++++
 src/mux_quic.c             | 40 +++++++++++++++++++++++-------------
 src/qcm_qmux.c             | 42 +++++++++++++++++++-------------------
 3 files changed, 56 insertions(+), 35 deletions(-)

-- 
2.56.1



Reply via email to