[PATCH] Fix handling of out-of-memory in get command.
Steven Grimm
sgrimm at facebook.com
Mon Nov 12 17:40:29 UTC 2007
This seems obviously correct to me. I will commit it. Thanks.
-Steve
On Nov 12, 2007, at 4:45 AM, Tomash Brechko wrote:
> Always send "SERVER_ERROR out of memory" when memory exhausted.
> Before the fix the code tried to append "END\r\n" to whatever there
> was in the buffer, which may produce bogus result because the buffer
> might not end in "\r\n". Also the result of add_iov() wasn't tested.
> ---
> trunk/server/memcached.c | 10 +++++++---
> 1 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/trunk/server/memcached.c b/trunk/server/memcached.c
> index 9e4271f..974eb81 100644
> --- a/trunk/server/memcached.c
> +++ b/trunk/server/memcached.c
> @@ -1224,9 +1224,13 @@ static inline void process_get_command(conn
> *c, token_t *tokens, size_t ntokens,
>
> if (settings.verbose > 1)
> fprintf(stderr, ">%d END\n", c->sfd);
> - add_iov(c, "END\r\n", 5);
> -
> - if (c->udp && build_udp_headers(c) != 0) {
> + /*
> + If the loop was terminated because of out-of-memory, it is not
> + reliable to add END\r\n to the buffer, because it might not end
> + in \r\n. So we send SERVER_ERROR instead.
> + */
> + if (key_token->value != NULL || add_iov(c, "END\r\n", 5) != 0
> + || (c->udp && build_udp_headers(c) != 0)) {
> out_string(c, "SERVER_ERROR out of memory");
> }
> else {
> --
> 1.5.3.5.529.ge3d6d
More information about the memcached
mailing list