Redis Cache - "Server Closed the connection" error

Pratik Mehta picture Pratik Mehta · Feb 11, 2017 · Viewed 8.4k times · Source

I was running some tests to understand the MaxMemory-Reserved & MaxMemory-Policy and we faced “Server Closed the connection” error few times when Redis DB was almost full. Here are the details:

1) Created the Redis Cache with Standard C1(1 GB) tier and chose “allkeys-lru” and max-memory-reserved as 50 MB

2) Ran the Redis Benchmark tool to add the Keys in Redis DB to make sure Redis DB is almost full.

3) As soon as DB reached around ~960-980 MB, again ran Benchmark tool to add some more keys and got following error. In which all scenarios this error can occur? enter image description here Note: The Connected_Clients value was 0 when we ran the info command just before we encountered this error.

4) At same time ran the info command on Azure Portal Console and got the output as “Error”. 5) This error lasted approximately for 2-3 Mins and we were able to add keys after that. And once we ran the info command again, we got following stat. Here we see that difference between used_memory and used_memory_rss is around 76 MB. Do you think the above error could be because of this?

info

Server redis_version:3.2.3

redis_mode:standalone

os:Windows

arch_bits:64

multiplexing_api:winsock_IOCP

hz:10

Clients

connected_clients:2

client_longest_output_list:0

client_biggest_input_buf:0

client_total_writes_outstanding:0

client_total_sent_bytes_outstanding:0

blocked_clients:0

Memory

used_memory:968991592

used_memory_human:924.10M

used_memory_rss:1049776128

used_memory_rss_human:1001.14M

used_memory_peak:1070912296

used_memory_peak_human:1021.30M

used_memory_lua:37888

maxmemory:1100000000

maxmemory_human:1.02G

maxmemory_policy:allkeys-lru

mem_allocator:jemalloc-3.6.0 #

Answer

Deepak picture Deepak · Feb 13, 2017

Most likely you are running into scenario of high un-authenticated connections. Redis-benchmark first creates all the client connections (in your case -c 400 connections) and then authenticates them. The delay in auth causes high number of unauthenticated connections from a single IP and Azure Redis Cache closes them for DOS protection. Hence, the error “Server closed the connection” You can try the redis-benchmark from here, which I have modified to authenticate as soon as a connection has been made and should solve this issue.