redis-rb icon indicating copy to clipboard operation
redis-rb copied to clipboard

Trying to send command strings to a closed connection

Open ajvondrak opened this issue 4 years ago • 0 comments

Hi, it's me again with some em-synchrony issues. 😅 Just for posterity (i.e., for #915), I'm getting errors akin to this:

undefined method `"*2\r\n$4\r\nLLEN\r\n$6\r\nmylist\r\n"' for nil:NilClass (NoMethodError)
redis-4.1.0/lib/redis/connection/synchrony.rb:121:in `write'
redis-4.1.0/lib/redis/client.rb:274:in `block in write'
redis-4.1.0/lib/redis/client.rb:253:in `io'
redis-4.1.0/lib/redis/client.rb:272:in `write'
redis-4.1.0/lib/redis/client.rb:231:in `block (3 levels) in process'
redis-4.1.0/lib/redis/client.rb:225:in `each'
redis-4.1.0/lib/redis/client.rb:225:in `block (2 levels) in process'
redis-4.1.0/lib/redis/client.rb:375:in `ensure_connected'
redis-4.1.0/lib/redis/client.rb:224:in `block in process'
redis-4.1.0/lib/redis/client.rb:312:in `logging'
redis-4.1.0/lib/redis/client.rb:223:in `process'
honeycomb-beeline-2.0.0/lib/honeycomb/integrations/redis.rb:107:in `process'
redis-4.1.0/lib/redis/client.rb:123:in `call'
redis-4.1.0/lib/redis.rb:923:in `block in mget'
redis-4.1.0/lib/redis.rb:50:in `block in synchronize'
lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
redis-4.1.0/lib/redis.rb:50:in `synchronize'
redis-4.1.0/lib/redis.rb:922:in `mget'

Not the most useful error message, but digging through the stack trace we see https://github.com/redis/redis-rb/blob/0546fe6c62de81843e8f0e9353cafba52d76eab8/lib/redis/connection/synchrony.rb#L125-L127 So we're attempting to write the Redis command string to the connection. But of course, people have the bad habit of overriding Object#send. 😑 So what appears to be happening is that #write is being called after a #disconnect: https://github.com/redis/redis-rb/blob/0546fe6c62de81843e8f0e9353cafba52d76eab8/lib/redis/connection/synchrony.rb#L120-L123 So it tries to call NilClass#send with the Redis command string, resulting in the complicated NoMethodError.

ajvondrak avatar Jun 17 '20 23:06 ajvondrak