开发者

Redis: weird protocol/network errors

开发者 https://www.devze.com 2023-01-15 23:28 出处:网络
I\'m running Redis and connecting from Ruby using ezmobius\'s Redis gem[1]. Periodically (about once a day) I get a series of exceptions in my Rails app caused by Redis returning strange results.

I'm running Redis and connecting from Ruby using ezmobius's Redis gem[1].

Periodically (about once a day) I get a series of exceptions in my Rails app caused by Redis returning strange results.

They are often triggered by an exception such at this:

Redis::ProtocolError: Protocol error, got '3' as initial reply byte                         

or

Redis::ProtocolError: Protocol error, got '9' as initial reply byte                      

or sometimes

Errno::EAGAIN: Resource temporarily unavailable - Timeout reading from the socket

It usually requires a restart of my Rails servers to clear up the connection problem. I'm running Fedora Core 8, Rails 2.3.8, Redis gem 2.0.3. I'开发者_如何学Gove got the system_timer gem installed. Anybody got any ideas how I can stop these errors?

[1]Redis gem


I've just noticed the same thing in my background workers, which store tasks in queues in Redis and also communicate through Redis pub/sub. Google results suggest that this can happen if you use the same Redis object from more than one thread... I'm not sure if this is the case in my app, I'll have to investigate this (but I do have threads there).


I had a slightly similar issue with

Errno::EAGAIN: Resource temporarily unavailable - Timeout reading from the socket

Turns out, my redis-server had a timeout set to 300 seconds on connections. After 5 minutes, redis was killing the connection to my workers and they were logging the error above.

If your socket timeouts are happening every x seconds, its no doubt redis killing your 'idle' connection!


When initializing the connection, make sure to pass the :thread_safe option:

Redis.connect(:thread_safe => true)
0

精彩评论

暂无评论...
验证码 换一张
取 消