• zhaozhao.zz's avatar
    Revert multi OOM limit and add multi buffer limit (#12961) · 85a834bf
    zhaozhao.zz authored
    Fix #9926 , and introduce an alternative method to prevent abuse of
    transactions:
    
    1. revert #5454 (which was blocking read-only transactions in OOM
    state), and break the tie of MULTI state memory usage and the server OOM
    state. Meaning that we'll limit the total memory a single client can
    queue, and do that unconditionally regardless of the server being OOM or
    not.
    2. to prevent abuse of transactions, we use the
    `client-query-buffer-limit` to restrict the size of the transaction.
    Because the commands cached in the MULTI/EXEC queue have not been
    executed yet, so they are also considered a part of the "query buffer"
    in a broader sense. In other words, the commands in the MULTI queue and
    the `querybuf` of the client together constitute the "query buffer".
    When they exceed the limit, the connection will be disconnected.
    
    The reasoning is that it's sensible to sends a single command with a
    huge (1GB) argument, and it's sensible to sends a transaction with many
    small commands, but it's probably not common to sends a long transaction
    with many huge arguments (will consume a lot of memory before even being
    executed).
    
    If anyone runs into that, they can simply increase the
    `client-query-buffer-limit` config.
    
    P.S. To prevent DDoS attacks, unauthenticated clients have a separate
    hard limit. Their query buffer should not exceed a maximum of 1MB. In
    other words, if the query buffer of an unauthenticated client exceeds
    1MB or the `client-query-buffer-limit` (if it is set to a value smaller
    than 1MB,), the connection will be disconnected.
    85a834bf
networking.c 178 KB