arthurnn / memcached

A Ruby interface to the libmemcached C client
Academic Free License v3.0
432 stars 127 forks source link

A get with bad key doesn't show the key in the error. #102

Closed jason-o-matic closed 12 years ago

jason-o-matic commented 12 years ago
1.9.3p194 :001 > $cache.get("'asdf []")
Memcached::ABadKeyWasProvidedOrCharactersOutOfRange: Key {}
    from vendor/bundle/ruby/1.9.1/gems/memcached-1.4.3/lib/memcached/memcached.rb:619:in `reraise'
    from vendor/bundle/ruby/1.9.1/gems/memcached-1.4.3/lib/memcached/memcached.rb:598:in `check_return_code'
    from vendor/bundle/ruby/1.9.1/gems/memcached-1.4.3/lib/memcached/memcached.rb:544:in `server_by_key'
    from vendor/bundle/ruby/1.9.1/gems/memcached-1.4.3/lib/memcached/memcached.rb:628:in `block in inspect_keys'
    from vendor/bundle/ruby/1.9.1/gems/memcached-1.4.3/lib/memcached/memcached.rb:627:in `map'
    from vendor/bundle/ruby/1.9.1/gems/memcached-1.4.3/lib/memcached/memcached.rb:627:in `inspect_keys'
    from vendor/bundle/ruby/1.9.1/gems/memcached-1.4.3/lib/memcached/memcached.rb:605:in `reraise'
    from vendor/bundle/ruby/1.9.1/gems/memcached-1.4.3/lib/memcached/memcached.rb:598:in `check_return_code'
    from vendor/bundle/ruby/1.9.1/gems/memcached-1.4.3/lib/memcached/memcached.rb:517:in `get'

This makes it much harder to figure out what the issue was from the exception info.

timhaines commented 12 years ago

Lazily +1'ing this. It goes through to re-raise twice as well. I'm not sure if that's a good thing.

timhaines commented 12 years ago

Actually, this exception (Memcached::ABadKeyWasProvidedOrCharactersOutOfRange) is being thrown when there's no problem with the keys. I've tried logging the keys when it occurs, and then retrying the multi_get, and it works without problem on the same keys.

evan commented 12 years ago

Would be curious to know what happens over the wire at that point. Maybe we could derive a reproducible case.

evan commented 12 years ago

On further inspection, MEMCACHED_BAD_KEY_PROVIDED is only thrown by client-side checks. You could try turning off :verify_key and seeing if you get a more revealing error (or no error).

I also see that the issue surrounding the missing key param is the double re-raise...will fix.

timhaines commented 12 years ago

Have disabled verify_key. Will see what blows up. Love the comments in the docs about this one: "Validate keys before accepting them. Never disable this."

timhaines commented 12 years ago

I get the same Memcached::ABadKeyWasProvidedOrCharactersOutOfRange (Key {}) error. Does the reraise cause this?

evan commented 12 years ago

It's possible the reraise is masking the real error, but are you sure it's off? That error should never be thrown.

timhaines commented 12 years ago

yes: @options={:retry_timeout=>1, :no_block=>true, :buffer_requests=>true, :noreply=>true, :binary_protocol=>false, :verify_key=>false},

I'll try updating to your fix soon.