Skip to content

Revert multi OOM limit and add multi buffer limit - #12961

Merged
oranagra merged 5 commits into
redis:unstablefrom
soloestoy:revert-multi-oom-limit
Jan 25, 2024
Merged

oranagra merged 5 commits into
redis:unstablefrom
soloestoy:revert-multi-oom-limit

Conversation

@soloestoy

@soloestoy soloestoy commented Jan 18, 2024 •

Copy link
Copy Markdown
Contributor

Fix #9926 , and introduce an alternative method to prevent abuse of transactions:

  1. revert MULTI: OOM err if cannot free enough memory in MULTI/EXEC context #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.

@soloestoy soloestoy changed the title Revert multi OOM limit and add multi state size limit Revert multi OOM limit and add multi buffer limit Jan 18, 2024
Comment thread src/config.c Resolved

@madolson madolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer #12888 over this, since clients will be getting an explicit error.

@soloestoy soloestoy added the release-notes indication that this issue needs to be mentioned in the release notes label Jan 24, 2024
@soloestoy

Copy link
Copy Markdown
Contributor Author

@oranagra @madolson please approve, and feel free to modify the top comment.

Comment thread src/networking.c Resolved
@oranagra

Copy link
Copy Markdown
Member

added a paragraph at the bottom of the description above, PTAL

@madolson

Copy link
Copy Markdown
Contributor

I'm fine merging it with or without the querybuf limit updates.

@soloestoy

Copy link
Copy Markdown
Contributor Author

I have added the restriction for unauthenticated clients to the top comment. Please review and confirm.

@oranagra
oranagra merged commit 85a834b into redis:unstable Jan 25, 2024
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jan 25, 2024
Code incorrectly set the limit value to 1024MB.
Introduced in redis#12961.
oranagra pushed a commit that referenced this pull request Jan 25, 2024
Code incorrectly set the limit value to 1024MB.
Introduced in #12961.
roggervalf pushed a commit to roggervalf/redis that referenced this pull request Feb 11, 2024
Fix redis#9926 , and introduce an alternative method to prevent abuse of
transactions:

1. revert redis#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.
roggervalf pushed a commit to roggervalf/redis that referenced this pull request Feb 11, 2024
Code incorrectly set the limit value to 1024MB.
Introduced in redis#12961.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Any command used in MULTI fails when used_memory > maxmemory

3 participants