Search code examples
rubymongodbreplicaset

replSetStepDown works, but an EOF error is returned to my Ruby mongo driver


I am interacting with my MongoDB ReplicaSet through my Ruby mongo driver, v. 2.6.2.

@mongo_client = Mongo::Client.new(@uri, connect: :replica_set).use("admin")

When I want to initiate a failover, I run this command

begin
  failover = @mongo_client.command(
    {
      replSetStepDown:            60,
      secondaryCatchUpPeriodSecs: 10,
      force:                      false
    }
  )
  Rails.logger.error "failover: #{failover}"
rescue Mongo::Error::SocketError => e
  Rails.logger.error "error: #{e.to_s.inspect}"
end

The command works, and the failover happens. But an exception is raised, that's why I have to rescue it:

error: EOFError: end of file reached

When I pass invalid arguments, I do get proper responses, for example:

failover: Mongo::Error::OperationFailure (stepdown period must be longer than secondaryCatchUpPeriodSecs (2)):

So it's only on successfull initiation that the exception is raised.

Any idea how to get a proper response, rather than an exception?


Solution

  • error: EOFError: end of file reached

    This is expected behavior in pre-4.2 servers, which close all connections when they step down. 4.2+ servers do not.

    Any idea how to get a proper response, rather than an exception?

    Use a 4.2+ server.