broadinstitute / single_cell_portal_core

Rails/Docker application for the Broad Institute's single cell RNA-seq data portal
https://singlecell.broadinstitute.org
BSD 3-Clause "New" or "Revised" License
62 stars 26 forks source link

Getting error, Mongo::Error::NoServerAvailable: No server is available matching preference #987

Closed genericdata closed 3 years ago

genericdata commented 3 years ago

I am attempting to deploy a private instance. I am getting the following error Mongo::Error::NoServerAvailable: No server is available matching preference when running:

bin/boot_docker -k (service account key path) -K (read-only service account key path) \
    -o (oauth client id) -S (oauth client secret) -N (portal namespace) -m (mongodb hostname) \
    -M (mongodb internal ip) -p (mongodb password)

Here is a subset of output after I added --trace --versbose to the line in sudo -E -u app -H bin/rake -A --verbose --trace RAILS_ENV=$PASSENGER_APP_ENV db:migrate in rails_local_setup.rb.

** Execute db:migrate
rake aborted!
Mongo::Error::NoServerAvailable: No server is available matching preference: #<Mongo::ServerSelector::Primary:0x47121701021520 tag_sets=[] max_staleness=nil> using server_selection_timeout=30 and local_threshold=0.015
/usr/local/rvm/gems/ruby-2.6.6/gems/mongo-2.6.1/lib/mongo/server_selector/selectable.rb:115:in `select_server'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongo-2.6.1/lib/mongo/collection/view/iterable.rb:41:in `block in each'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongo-2.6.1/lib/mongo/retryable.rb:45:in `read_with_retry'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongo-2.6.1/lib/mongo/collection/view/iterable.rb:40:in `each'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid-6.4.1/lib/mongoid/query_cache.rb:222:in `each'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid-6.4.1/lib/mongoid/contextual/mongo.rb:133:in `each'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid-6.4.1/lib/mongoid/contextual/mongo.rb:325:in `map'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid-6.4.1/lib/mongoid/contextual/mongo.rb:325:in `map'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid-6.4.1/lib/mongoid/contextual.rb:20:in `map'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/active_record_ext/migrations.rb:233:in `get_all_versions'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/active_record_ext/migrations.rb:372:in `migrated'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/active_record_ext/migrations.rb:273:in `current_version'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/active_record_ext/migrations.rb:290:in `block in migrate'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/active_record_ext/migrations.rb:290:in `each'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/active_record_ext/migrations.rb:290:in `detect'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/active_record_ext/migrations.rb:290:in `migrate'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/active_record_ext/migrations.rb:210:in `up'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/active_record_ext/migrations.rb:195:in `migrate'
/usr/local/rvm/gems/ruby-2.6.6/gems/mongoid_rails_migrations-1.1.1/lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake:42:in `block (2 levels) in <main>'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `block in execute'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `each'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `execute'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:199:in `invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/task.rb:188:in `invoke'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:160:in `invoke_task'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `each'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `block in top_level'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:125:in `run_with_threads'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:110:in `top_level'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:83:in `block in run'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:186:in `standard_exception_handling'
/usr/local/rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rake-13.0.3/lib/rake/application.rb:80:in `run'
bin/rake:4:in `<main>'
Tasks: TOP => db:migrate
*** COMPLETED ***

My DB is hosted on MongoDB Atlas with the single_cell user created. From my VM I can access the DB using:

mongo "mongodb+srv://host.mongodb.net/" --username single_cell

I have also attempted to install mongoDB locally on the machine, but the results are the same.

bin/boot_docker -m localhost -M 127.0.0.1 -p (mongodb password) ...

What am I doing wrong? Thank you.

bistline commented 3 years ago

Eric -

We have never tested using Single Cell Portal with MongoDB Atlas - we have always deployed our own via Docker on a separate GCP virtual machine that we connect to over an IP address. That being said, if you can connect from the command line to your remote instance, SCP should be able to see it. However, you shouldn't pass the --username flag as this is configured in config/mongoid.yml. Since you are not deploying your database as a VM in GCP like we do, you should also pass the same value for MONGO_LOCALHOST and MONGO_INTERNAL_IP.

According to the docs for Mongoid, it looks as though they want you to pass the value for a hosted cluster as uri and not hosts. You could try editing config/mongoid.yml and use the syntax they provide.

If you are trying to use MongoDB locally, you will have to do so via Docker and not natively on your machine. Since we mount volumes directly inside the container, we cannot use the --host networking mode. This means that calling localhost inside Docker refers to the Docker container itself, and not your local machine. This is why it cannot see mongo running locally as it has no way of resolving localhost back to your computer.

I would recommend using the official mongo Docker image if you want to test locally.

Hopefully that will resolve you connection issue. Please let me know if you run into any other issues - we haven't had someone attempt to deploy their own instance in a while, and it would be great to get some feedback on areas where our documentation is out-of-date or incomplete.

Jon

genericdata commented 3 years ago

Thank you.

After commenting out all lines under development within config/mongoid.yml and adding the uri line, I do not get the error.

development:
  clients:
    default:
       uri: mongodb+srv://single_cell:pass@yourcluster.mongodb.net/single_cell_portal_development?retryWrites=true&w=majority