dalli 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dalli might be problematic. Click here for more details.
- data/History.md +5 -0
- data/TODO.md +0 -1
- data/lib/dalli/client.rb +2 -2
- data/lib/dalli/server.rb +12 -9
- data/lib/dalli/version.rb +1 -1
- data/test/test_network.rb +3 -3
- metadata +2 -2
    
        data/History.md
    CHANGED
    
    
    
        data/TODO.md
    CHANGED
    
    
    
        data/lib/dalli/client.rb
    CHANGED
    
    | @@ -21,7 +21,7 @@ module Dalli | |
| 21 21 | 
             
                #
         | 
| 22 22 | 
             
                def initialize(servers=nil, options={})
         | 
| 23 23 | 
             
                  @ring = Dalli::Ring.new(
         | 
| 24 | 
            -
                    Array( | 
| 24 | 
            +
                    Array(env_servers || servers).map do |s| 
         | 
| 25 25 | 
             
                      Dalli::Server.new(s)
         | 
| 26 26 | 
             
                    end, options
         | 
| 27 27 | 
             
                  )
         | 
| @@ -148,7 +148,7 @@ module Dalli | |
| 148 148 | 
             
                end
         | 
| 149 149 |  | 
| 150 150 | 
             
                def env_servers
         | 
| 151 | 
            -
                  ENV['MEMCACHE_SERVERS'].split(',')
         | 
| 151 | 
            +
                  ENV['MEMCACHE_SERVERS'] ? ENV['MEMCACHE_SERVERS'].split(',') : nil
         | 
| 152 152 | 
             
                end
         | 
| 153 153 |  | 
| 154 154 | 
             
                # Chokepoint method for instrumentation
         | 
    
        data/lib/dalli/server.rb
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            require 'socket'
         | 
| 2 | 
            +
            require 'timeout'
         | 
| 2 3 |  | 
| 3 4 | 
             
            module Dalli
         | 
| 4 5 | 
             
              class Server
         | 
| @@ -263,16 +264,16 @@ module Dalli | |
| 263 264 | 
             
                  end
         | 
| 264 265 | 
             
                end
         | 
| 265 266 |  | 
| 266 | 
            -
                def read(count)
         | 
| 267 | 
            +
                def read(count, socket=connection)
         | 
| 267 268 | 
             
                  begin
         | 
| 268 269 | 
             
                    value = ''
         | 
| 269 270 | 
             
                    begin
         | 
| 270 271 | 
             
                      loop do
         | 
| 271 | 
            -
                        value <<  | 
| 272 | 
            +
                        value << socket.sysread(count)
         | 
| 272 273 | 
             
                        break if value.size == count
         | 
| 273 274 | 
             
                      end
         | 
| 274 275 | 
             
                    rescue Errno::EAGAIN, Errno::EWOULDBLOCK
         | 
| 275 | 
            -
                      if IO.select([ | 
| 276 | 
            +
                      if IO.select([socket], nil, nil, TIMEOUT)
         | 
| 276 277 | 
             
                        retry
         | 
| 277 278 | 
             
                      else
         | 
| 278 279 | 
             
                        raise Timeout::Error, "IO timeout"
         | 
| @@ -381,14 +382,16 @@ module Dalli | |
| 381 382 | 
             
                def sasl_authentication(socket)
         | 
| 382 383 | 
             
                  init_sasl if !defined?(::SASL)
         | 
| 383 384 |  | 
| 385 | 
            +
                  Dalli.logger.info { "Dalli/SASL authenticating as #{username}" }
         | 
| 386 | 
            +
             | 
| 384 387 | 
             
                  # negotiate
         | 
| 385 388 | 
             
                  req = [REQUEST, OPCODES[:auth_negotiation], 0, 0, 0, 0, 0, 0, 0].pack(FORMAT[:noop])
         | 
| 386 389 | 
             
                  socket.write(req)
         | 
| 387 | 
            -
                  header =  | 
| 390 | 
            +
                  header = read(24, socket)
         | 
| 388 391 | 
             
                  raise Dalli::NetworkError, 'No response' if !header
         | 
| 389 392 | 
             
                  (extras, status, count) = header.unpack(NORMAL_HEADER)
         | 
| 390 393 | 
             
                  raise Dalli::NetworkError, "Unexpected message format: #{extras} #{count}" unless extras == 0 && count > 0
         | 
| 391 | 
            -
                  content =  | 
| 394 | 
            +
                  content = read(count, socket)
         | 
| 392 395 | 
             
                  return (Dalli.logger.debug("Authentication not required/supported by server")) if status == 0x81
         | 
| 393 396 | 
             
                  mechanisms = content.split(' ')
         | 
| 394 397 |  | 
| @@ -400,16 +403,16 @@ module Dalli | |
| 400 403 | 
             
                  req = [REQUEST, OPCODES[:auth_request], mechanism.size, 0, 0, 0, mechanism.size + msg.size, 0, 0, mechanism, msg].pack(FORMAT[:auth_request])
         | 
| 401 404 | 
             
                  socket.write(req)
         | 
| 402 405 |  | 
| 403 | 
            -
                  header =  | 
| 406 | 
            +
                  header = read(24, socket)
         | 
| 404 407 | 
             
                  raise Dalli::NetworkError, 'No response' if !header
         | 
| 405 408 | 
             
                  (extras, status, count) = header.unpack(NORMAL_HEADER)
         | 
| 406 409 | 
             
                  raise Dalli::NetworkError, "Unexpected message format: #{extras} #{count}" unless extras == 0 && count > 0
         | 
| 407 | 
            -
                  content =  | 
| 410 | 
            +
                  content = read(count, socket)
         | 
| 411 | 
            +
                  return Dalli.logger.info("Dalli/SASL: #{content}") if status == 0
         | 
| 412 | 
            +
             | 
| 408 413 | 
             
                  raise Dalli::NetworkError, "Error authenticating: #{status}" unless status == 0x21
         | 
| 409 414 | 
             
                  (step, msg) = sasl.receive('challenge', content)
         | 
| 410 415 | 
             
                  raise Dalli::NetworkError, "Authentication failed" if sasl.failed? || step != 'response'
         | 
| 411 | 
            -
             | 
| 412 | 
            -
                  
         | 
| 413 416 | 
             
                end
         | 
| 414 417 | 
             
              end
         | 
| 415 418 | 
             
            end
         | 
    
        data/lib/dalli/version.rb
    CHANGED
    
    
    
        data/test/test_network.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            require 'helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            class TestNetwork < Test::Unit::TestCase
         | 
| 4 | 
            -
             | 
| 4 | 
            +
             | 
| 5 5 | 
             
              context 'assuming a bad network' do
         | 
| 6 6 |  | 
| 7 7 | 
             
                should 'handle connection refused' do
         | 
| @@ -10,12 +10,12 @@ class TestNetwork < Test::Unit::TestCase | |
| 10 10 | 
             
                    dc.get 'foo'
         | 
| 11 11 | 
             
                  end
         | 
| 12 12 | 
             
                end
         | 
| 13 | 
            -
             | 
| 13 | 
            +
             | 
| 14 14 | 
             
                context 'with a fake server' do
         | 
| 15 15 |  | 
| 16 16 | 
             
                  should 'handle connection reset' do
         | 
| 17 17 | 
             
                    memcached_mock(lambda {|sock| sock.close }) do
         | 
| 18 | 
            -
                      assert_error Dalli::NetworkError, /ECONNRESET/ do
         | 
| 18 | 
            +
                      assert_error Dalli::NetworkError, /ECONNRESET|EOFError/ do
         | 
| 19 19 | 
             
                        dc = Dalli::Client.new('localhost:19123')
         | 
| 20 20 | 
             
                        dc.get('abc')
         | 
| 21 21 | 
             
                      end
         |