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

Adds checking for the phrase 'not authorized' to the unauthorized check,... #191

Merged
merged 2 commits into from
May 6, 2013

Conversation

jonhyman
Copy link
Contributor

@jonhyman jonhyman commented May 3, 2013

... part two of #174 and #171


I'm getting the unauthorized errors again sporadically. Looking at the error message, it also says "not authorized for query" separately from saying "failed with error "unauthorized""

As such, check for both.

@durran durran merged commit 5962cbb into mongoid:1.4.0-stable May 6, 2013
@jonhyman
Copy link
Contributor Author

jonhyman commented May 6, 2013

@durran, I'm still getting errors even with this pull. I added some logs on my server, here's what I found:

In reply.rb#unauthorized?
[INFO] Moped unauthorized, result is {"$err"=>"not authorized for query on experimental.itunes_connect_credentials", "code"=>16549}
[INFO] Moped unauthorized returning 0

In node.rb#query
[INFO] Moped query unauthorized, trying to reconnect.

Then immediately in my code:
results was [{"$err"=>"not authorized for query on experimental.staging", "code"=>16549}]

I think there might be a problem in #query in node.rb. Thoughts on this change?

def query(database, collection, selector, options = {})
      operation = Protocol::Query.new(database, collection, selector, options)

      process(operation) do |reply|
        if reply.query_failed?
          if reply.unauthorized? && auth.has_key?(database)
            # If we got here, most likely this is the case of Moped
            # authenticating successfully against the node originally, but the
            # node has been reset or gone down and come back up. The most
            # common case here is a rs.stepDown() which will reinitialize the
            # connection. In this case we need to requthenticate and try again,
            # otherwise we'll just raise the error to the user.
            login(database, *auth[database])

            # ADDED THE RETURN HERE
            return query(database, collection, selector, options)
          else
            raise Errors::QueryFailure.new(operation, reply.documents.first)
          end
        end
        reply
      end
    end

Because my thought is that even though you're reconnecting, you're returning the old reply. I'm going to try that.

@ghost ghost assigned durran May 6, 2013
@durran
Copy link
Member

durran commented May 6, 2013

Ah good catch... Which is why on master this is probably ok:

https://github.com/mongoid/moped/blob/master/lib/moped/operation/read.rb#L52

@jonhyman
Copy link
Contributor Author

jonhyman commented May 6, 2013

I'm currently testing that change out on my experimental environment. Unfortunately, it takes about 6 hours for the unauthorized error to appear, but with my logging I added I should be able to determine if it works. If it works, I'll submit a pull.

@durran
Copy link
Member

durran commented May 6, 2013

Sweet - thanks for all your help again.

@jonhyman
Copy link
Contributor Author

jonhyman commented May 6, 2013

It seems to have helped from what I can tell. Opened #192

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.

None yet

2 participants