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

Don't clear the auth when disconnecting, it can mess up queries on the n... #286

Merged
merged 1 commit into from
Jun 15, 2014

Conversation

jonhyman
Copy link
Contributor

...ode that are unauthorized due to a failover.

See #272 for backstory

…e node that are unauthorized due to a failover.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0%) when pulling a748995 on jonhyman:feature/no-auth-clear-master into a44b4e1 on mongoid:master.

@arthurnn
Copy link
Contributor

Can you write a test case to illustrate the issue?

thanks for the PR

@jonhyman
Copy link
Contributor Author

@arthurnn yeah I'll try to write a test for it.

@jonhyman
Copy link
Contributor Author

Hey @arthurnn I'm having a bit of a hard time writing this test and have hit my timebox of 45 minutes. Here's what I have so far, but the problem is that it's hard to exactly mimic the behavior:

context "when an authorization error happens and the cluster gets disconnected" do
      before(:all) do
        @session = Support::MongoHQ.auth_session
      end

      let(:users) do
        @session.with(safe: true)[:users]
      end

      before do
        users.insert(documents)
      end

      it "retries" do
        call_count0 = 0
        call_count1 = 0
        Moped::Protocol::Reply.any_instance.stub(:query_failed?) do
          call_count0 += 1
          call_count0 == 1 ? true : false
        end
        Moped::Protocol::Reply.any_instance.stub(:unauthorized?) do
          call_count1 += 1
          call_count1 == 1 ? true : false
        end
        query = users.find(scope: scope).sort(_id: -1)
        query.one
        users.database.session.cluster.nodes.each do |node|
          node.stub(:connect).once.and_raise(Moped::Errors::ConnectionFailure.new)
        end
        users.database.session.cluster.__send__(:disconnect)
        query.one.should eq documents.last
      end
    end

the place where I think this bug was coming up is when ensure_connected would get a ConnectionFailure, disconnect (which would clear credentials, and then reconnect but the credentials would be gone.

The way in which I came up with this pull through debugging was that I added debug print statements throughout the Moped code gem on my staging servers and constantly failed over while executing queries. I was never able to reproduce it locally.

@jonhyman
Copy link
Contributor Author

If you think you can help with the test, that'd be great; otherwise, I think that this pull should get merged in regardless because, as-is, it definitely has the potential for problems in heavily trafficked installations.

arthurnn added a commit that referenced this pull request Jun 15, 2014
Don't clear the auth when disconnecting, it can mess up queries on the n...
@arthurnn arthurnn merged commit dec51d6 into mongoid:master Jun 15, 2014
@arthurnn
Copy link
Contributor

indeed this make sense.. i will merge it for now.. and working on so good way to add a regression test for it.
thanks

@edejong
Copy link

edejong commented Jun 15, 2014

This patch for some reason immediately results in failed with error "unauthorized" in my rails project.

See #287

arthurnn added a commit that referenced this pull request Jun 16, 2014
…aster"

This reverts commit dec51d6, reversing
changes made to b6e499b.

[fixes #287]
@arthurnn
Copy link
Contributor

Had to revert this due errors happening reported from #287.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants