Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Mark node as not down when alive connection was acquired
Browse files Browse the repository at this point in the history
I've discovered this problem when running latest moped:master with thin server
in threaded mode (`--threaded`). We have one Mongo server and when it
goes down for a few secs, some of our app servers are unable to reconnect to
it. We see lots of log output like this:

   MOPED: Retrying connection attempt 1 more time(s), nodes is [], seeds are
   MOPED: Retrying connection attempt 1 more time(s), nodes is [], seeds are
   MOPED: Retrying connection attempt 1 more time(s), nodes is [], seeds are
  • Loading branch information
a-chernykh committed Aug 13, 2015
1 parent 803bbcd commit 9767f66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/moped/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ def ensure_connected(&block)

begin
connection do |conn|
connect(conn) unless conn.alive?
if conn.alive?
@down_at = nil
else
connect(conn)
end
conn.apply_credentials(@credentials)
stack(:connection) << conn
yield(conn)
Expand Down
15 changes: 15 additions & 0 deletions spec/moped/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,21 @@
end
end
end

context 'when node was down' do
before { node.down! }

context 'and good connection popped out of the pool' do
before { allow_any_instance_of(Moped::Connection).to receive(:alive?).and_return true }

it 'marks node as not down' do
node.ensure_connected do
node.command("admin", ping: 1)
end
expect(node).not_to be_down
end
end
end
end

describe "#initialize" do
Expand Down

0 comments on commit 9767f66

Please sign in to comment.