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

4ba8add breaks authentication when Unicorn is loaded #243

Closed
glebtv opened this issue Dec 4, 2013 · 9 comments
Closed

4ba8add breaks authentication when Unicorn is loaded #243

glebtv opened this issue Dec 4, 2013 · 9 comments
Assignees

Comments

@glebtv
Copy link

glebtv commented Dec 4, 2013

HEAD is now at da92f1b... Add doc for cursor method

2.0.0p353 :002 > Page.count
 => 10 

HEAD is now at 4ba8add... Dont re-login when using multi-session

Loading production environment (Rails 4.0.2)
2.0.0p353 :001 > Page.count
Moped::Errors::OperationFailure: The operation: #<Moped::Protocol::Command
  @length=70
  @request_id=5
  @response_to=0
  @op_code=2004
  @flags=[]
  @full_collection_name="vv.$cmd"
  @skip=0
  @limit=-1
  @selector={:count=>"pages", :query=>{}}
  @fields=nil>
failed with error "unauthorized"
    from /home/vv/moped/lib/moped/operation/read.rb:50:in `block in execute'
    from /home/vv/moped/lib/moped/node.rb:595:in `[]'
    from /home/vv/moped/lib/moped/node.rb:595:in `block (2 levels) in flush'
    from /home/vv/moped/lib/moped/node.rb:594:in `map'
    from /home/vv/moped/lib/moped/node.rb:594:in `block in flush'
    from /home/vv/moped/lib/moped/node.rb:618:in `block in logging'
    from /home/vv/.rvm/gems/ruby-2.0.0-p353@vv/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in `block in instrument'
    from /home/vv/.rvm/gems/ruby-2.0.0-p353@vv/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /home/vv/.rvm/gems/ruby-2.0.0-p353@vv/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in `instrument'
    from /home/vv/moped/lib/moped/instrumentable.rb:31:in `instrument'
    from /home/vv/moped/lib/moped/node.rb:617:in `logging'
    from /home/vv/moped/lib/moped/node.rb:588:in `flush'
    from /home/vv/moped/lib/moped/node.rb:392:in `process'
    from /home/vv/moped/lib/moped/operation/read.rb:48:in `execute'
    from /home/vv/moped/lib/moped/node.rb:649:in `read'
    from /home/vv/moped/lib/moped/node.rb:90:in `command'
... 7 levels...
    from /home/vv/moped/lib/moped/read_preference/selectable.rb:65:in `call'
    from /home/vv/moped/lib/moped/read_preference/selectable.rb:65:in `with_retry'
    from /home/vv/moped/lib/moped/read_preference/primary.rb:54:in `with_node'
    from /home/vv/moped/lib/moped/database.rb:72:in `command'
    from /home/vv/moped/lib/moped/query.rb:41:in `count'
    from /home/vv/mongoid/lib/mongoid/contextual/mongo.rb:60:in `block in count'
    from /home/vv/mongoid/lib/mongoid/contextual/mongo.rb:449:in `try_cache'
    from /home/vv/mongoid/lib/mongoid/contextual/mongo.rb:60:in `count'
    from /home/vv/mongoid/lib/mongoid/contextual.rb:19:in `count'
    from /home/vv/mongoid/lib/mongoid/findable.rb:49:in `count'
    from (irb):1
    from /home/vv/.rvm/gems/ruby-2.0.0-p353@vv/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
    from /home/vv/.rvm/gems/ruby-2.0.0-p353@vv/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
    from /home/vv/.rvm/gems/ruby-2.0.0-p353@vv/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'2.0.0p353 :002 > 

The setup is a simple single local instance with authentication enabled

@glebtv
Copy link
Author

glebtv commented Dec 4, 2013

Config is:

production:
  sessions:
    default:
      database: vv
      username: vv
      password: pass
      hosts:
        - localhost:27017
  options:

@glebtv
Copy link
Author

glebtv commented Dec 4, 2013

On another app, i found that commit cd4989b Merge pull request #228 from mongoid/conn_pool_checkin
also breaks authentication, but in an another way, don't know if it's related:

HEAD is now at a830152... mongoid/mongoid#3366 Issue with namespace

Loading production environment (Rails 4.0.2)
2.0.0p353 :001 > Page.count
 => 6 

HEAD is now at cd4989b... Merge pull request #228 from mongoid/conn_pool_checkin

Loading production environment (Rails 4.0.2)
2.0.0p353 :001 > Page.count
Moped::Errors::AuthenticationFailure: The operation: #<Moped::Protocol::Commands::Authenticate
  @length=154
  @request_id=2
  @response_to=0
  @op_code=2004
  @flags=[]
  @full_collection_name="province.$cmd"
  @skip=0
  @limit=-1
  @selector={:authenticate=>1, :user=>"province", :nonce=>"69144b0679fa0b18", :key=>"4153ead8670719a4b1e05306c2b04e91"}
  @fields=nil>
failed with error 18: "auth fails"

See https://github.com/mongodb/mongo/blob/master/docs/errors.md
for details about this error.
    from /home/province/moped/lib/moped/authenticatable.rb:68:in `block in login'
    from /home/province/moped/lib/moped/node.rb:130:in `block in connection'
    from /home/province/moped/lib/moped/connection/pool.rb:159:in `with_connection'
    from /home/province/moped/lib/moped/node.rb:129:in `connection'
    from /home/province/moped/lib/moped/authenticatable.rb:65:in `login'
    from /home/province/moped/lib/moped/authenticatable.rb:28:in `block in apply_credentials'
    from /home/province/moped/lib/moped/authenticatable.rb:26:in `each'
    from /home/province/moped/lib/moped/authenticatable.rb:26:in `apply_credentials'
    from /home/province/moped/lib/moped/cluster.rb:227:in `block in with_primary'
    from /home/province/moped/lib/moped/node.rb:212:in `block in ensure_primary'
    from /home/province/moped/lib/moped/executable.rb:25:in `execute'
    from /home/province/moped/lib/moped/node.rb:211:in `ensure_primary'
    from /home/province/moped/lib/moped/cluster.rb:226:in `with_primary'
    from /home/province/moped/lib/moped/read_preference/primary.rb:55:in `block in with_node'
    from /home/province/moped/lib/moped/read_preference/selectable.rb:65:in `call'
    from /home/province/moped/lib/moped/read_preference/selectable.rb:65:in `with_retry'
    from /home/province/moped/lib/moped/read_preference/primary.rb:54:in `with_node'
    from /home/province/moped/lib/moped/database.rb:72:in `command'
    from /home/province/moped/lib/moped/query.rb:41:in `count'
    from /home/province/.rvm/gems/ruby-2.0.0-p353@province/bundler/gems/mongoid-ec65b665430a/lib/mongoid/contextual/mongo.rb:60:in `block in count'
    from /home/province/.rvm/gems/ruby-2.0.0-p353@province/bundler/gems/mongoid-ec65b665430a/lib/mongoid/contextual/mongo.rb:449:in `try_cache'
    from /home/province/.rvm/gems/ruby-2.0.0-p353@province/bundler/gems/mongoid-ec65b665430a/lib/mongoid/contextual/mongo.rb:60:in `count'
    from /home/province/.rvm/gems/ruby-2.0.0-p353@province/bundler/gems/mongoid-ec65b665430a/lib/mongoid/contextual.rb:19:in `count'
    from /home/province/.rvm/gems/ruby-2.0.0-p353@province/bundler/gems/mongoid-ec65b665430a/lib/mongoid/findable.rb:49:in `count'
    from (irb):1
    from /home/province/.rvm/gems/ruby-2.0.0-p353@province/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
    from /home/province/.rvm/gems/ruby-2.0.0-p353@province/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
    from /home/province/.rvm/gems/ruby-2.0.0-p353@province/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
    from bin/rails:4:in `require'

@glebtv
Copy link
Author

glebtv commented Dec 4, 2013

However strange it might sound, the first problem only happens if Unicorn is added to Gemfile (and it is reproducible in an empty app, with just Unicorn added to gemfile, even in console). Remove Unicorn - and it goes away. Any ideas what to do from here?

@glebtv
Copy link
Author

glebtv commented Dec 4, 2013

It seems to start working, if I remove
https://github.com/mongoid/mongoid/blob/master/lib/mongoid/railtie.rb#L116-L118
this 3 lines
Removing them seems to fix it.

@florentmorin
Copy link

@glebtv : same experience, same result.

@GeirT
Copy link

GeirT commented Dec 5, 2013

@glebtv : Solved it for me too, thanks.

@glebtv
Copy link
Author

glebtv commented Dec 5, 2013

@GeirT It's not a real solution since it seems that in case of a disconnect it will fail again.
I don't recommend to really delete this lines and use it like that anywhere near production.

@arthurnn
Copy link
Contributor

This should be fixed on latest master. via 8a7719f and 9a88cd9

@jasonkarns
Copy link

as a reminder (because I forgot myself), you'll have to explicitly add moped to the Gemfile. pointing to mongoid master isn't enough

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

No branches or pull requests

5 participants