Skip to content

Commit

Permalink
Fix immediate retry of socket failures, fixes petergoldsteinGH-91
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed May 29, 2011
1 parent e556e45 commit 6ac1ca6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
11 changes: 11 additions & 0 deletions History.md
@@ -1,6 +1,17 @@
Dalli Changelog
=====================

1.1.0
=======

- Remove support for Rails 2.3, add support for Rails 3.1
- Fix socket failure retry logic, now you can restart memcached and Dalli won't complain!

1.0.5
=======

- Fix socket failure retry logic, now you can restart memcached and Dalli won't complain!

1.0.4
=======

Expand Down
2 changes: 2 additions & 0 deletions lib/dalli/server.rb
Expand Up @@ -98,7 +98,9 @@ def failure!
if @fail_count >= options[:socket_max_failures]
down!
else
close
sleep(options[:socket_failure_delay]) if options[:socket_failure_delay]
raise Dalli::NetworkError, "Socket operation failed, retrying..."
end
end

Expand Down
23 changes: 21 additions & 2 deletions test/test_failover.rb
Expand Up @@ -2,19 +2,38 @@

class TestFailover < Test::Unit::TestCase
context 'assuming some bad servers' do

should 'silently reconnect if server hiccups' do
memcached(29125) do
dc = Dalli::Client.new ['localhost:29125']
dc.set 'foo', 'bar'
foo = dc.get 'foo'
assert_equal foo, 'bar'

memcached_kill(29125)
memcached(29125) do

foo = dc.get 'foo'
assert_nil foo

memcached_kill(29125)
end
end
end

should 'handle graceful failover' do
memcached(29125) do
memcached(29126) do
dc = Dalli::Client.new ['localhost:29125', 'localhost:29126']
dc.set 'foo', 'bar'
foo = dc.get 'foo'
assert foo, 'bar'
assert_equal foo, 'bar'

memcached_kill(29125)

dc.set 'foo', 'bar'
foo = dc.get 'foo'
assert foo, 'bar'
assert_equal foo, 'bar'

memcached_kill(29126)

Expand Down
4 changes: 0 additions & 4 deletions test/test_ring.rb
Expand Up @@ -77,10 +77,6 @@ class TestRing < Test::Unit::TestCase
assert_equal 1, dc.stats.values.compact.count

memcached(29126) do
assert_equal 1, dc.stats.values.compact.count

sleep(down_retry_delay+0.1)

assert_equal 2, dc.stats.values.compact.count
end
end
Expand Down

0 comments on commit 6ac1ca6

Please sign in to comment.