Rails application Error Incomplete response received from application - ruby-on-rails

I have 3 applications ruby on rails in shared hosting, one of them SOMETIMES throw an error:
White screen and message:
Incomplete response received from application
I can't reproduce the error, only sometimes the application throw the error.
In the application log there aren't any error.
How you said me in the comments I search for config/secrets.yml. This doesn't exist in my application.
I create this with the config/initializer/secret_token.rb.
My config/secrets.yml:
development:
secret_key_base: "key in secret_token"
test:
secret_key_base: "key in secret_token"
production:
secret_key_base: "key in secret_token"
Then I deleted secret_token and restart server: "touch tmp/restart.txt".
The error still appears.

Related

ActiveRecord connection errors with PGBouncer

The bounty expires in 7 days. Answers to this question are eligible for a +100 reputation bounty.
CWitty wants to draw more attention to this question.
We recently introduce PGBouncer into our stack as we were exhausting our connections to our RDS instance. Upon doing so we started to see all sorts of connection exceptions which I posted below. The only thing of note is that we use multiple databases via Rails built in multi-db support. Only the primary/writer instance is going through PGBouncer at the moment and that is where we are seeing all of the exceptions, the reader connections seem to be fine.
I'm wondering if we need to fine tune some of the timeout or connection sizes a bit or what else could be causing this.
Exceptions
ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
ActiveRecord::ConnectionNotEstablished: connection to server at "{db server IP}", port 5432 failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing
ActiveRecord::StatementInvalid: PG::ConnectionBad: PQsocket() can't get socket descriptor
PGBouncer Config
We're running quite a few smaller instances of PGBouncer since it is single process and I believe single threaded as well. We plan to fine tune this a bit later.
[databases]
production = our_connection_string
[pgbouncer]
max_client_conn = 500
pool_mode = transaction
default_pool_size = 200
server_idle_timeout = 30
reserve_pool_size = 0
Rails DB Config
default: &default
adapter: postgis
postgis_extension: true
encoding: unicode
pool: <%= ENV['DB_POOL'] || ENV['RAILS_MAX_THREADS'] || 5 %>
idle_timeout: 300
checkout_timeout: 5
schema_search_path: public, tiger
prepared_statements: false
production:
primary:
<<: *default
url: <%= ENV[DATABASE_URL] %>
primary_replica:
<<: *default
url: <%= ENV[DATABASE_REPLICA_URL] %>
Update 1
We attempted going with the default value for server_idle_timeout of 600 seconds and that doesn't seem to have made a difference.

pgsync cannot connect to Amazon PostgreSQL database on RDS

I am trying to synchronize data from my local dev database to a test DB running on Amazon RDS using the pgsync gem.
My .pgsync.yml page is simple:
from: postgres://localhost:5432/imports_development?sslmode=require
to: [See attempts below]
exclude:
- [A few tables]
I have tried many approaches but none of them are working. Here are all approaches and the error messages I've received:
to: postgres://awsuser:mypassword#imports-test.abcdefg.us-east-1.rds.amazonaws.com/postgres?sslca=config/rds-combined-ca-bundle.pem
=> invalid URI query parameter: "sslca"
to: postgres://awsuser:mypassword#imports-test.abcdefg.us-east-1.rds.amazonaws.com
=> connection to server at "52.4.150.10", port 5432 failed: FATAL: database "awsuser" does not exist
to: $(heroku config:get DATABASE_URL)
=> invalid URI parameter: "sslca"
to: imports-test.abcdefg.us-east-1.rds.amazonaws.com
=> connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "imports-test.abcdefg.us-east-1.rds.amazonaws.com" does not exist
These are the credentials used by database.yml for the RDS database:
rds_db_name: postgres
rds_username: awsuser
rds_password: mypassword
rds_hostname: imports-test.abcdefg.us-east-1.rds.amazonaws.com
rds_port: 5432
I can connect to both databases with rails console, so it should just be a matter of getting the above statements right. What is missing here?
Have you tried postgres://awsuser:mypassword#imports-test.abcdefg.us-east-1.rds.amazonaws.com/postgres ? Attempt no.2 seems to work, but doesn't include the DB name, based on the error.
Roughly the URI is in the format:
postgres://{USER}:{PASS}#{HOSTNAME}/{DBNAME}
The ?sslca=123 and other options AFTER ? (the query string) is meant as options. Not all clients support all options here.

Incorrect credentials response in Rails 6

Rails 6
I created the credentials file, as follows:
EDITOR=vi rails credentials:edit
production:
mysql:
db: acme-production
user: deploy
password: xxxxxxxxxxxx
smartagent:
token: lnroftb7sgr8c7f1ogqvij24xl
test:
mysql:
db: acme-test
user: deploy
password: xxxxxxxxxxxx
smartagent:
token: lnroftb7sgr8c7f1ogqvij24xl
secret_key_base: xxxxxxxxxxxxxx
master.key is in the correct place (in the config folder, locally, and as an environment setting on the server).
I am having trouble with the smartagent token.
When I do:
rails c
and
Rails.application.credentials.dig(Rails.env.to_sym, :mysql, :db)
I get:
=> "acme-test"
However, when I do:
Rails.application.credentials.dig(Rails.env.to_sym, :smartagent, :token)
I get:
=> nil
Any idea why this might be happening?
Solution:
I deleted the credentials file, re-populated it, and restarted the Rails app. That fixed the problem, so this must have been either an indentation issue (spaces vs tabs), or that the server had not restarted properly, after earlier changes were made

How to properly connect ROR with Oracle database with Ruby-OCI8 gem?

I'm trying to use Oracle Database Xe on my ruby on rails app
but I'm having a lot of trouble with my database connection I'm currently not sure what the problem is, but according to what I have read I may have a problem with my TNS setup the error message that I'am having is
OCIError: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
The error appears every time I try to run rake db:migrate
on my rails console I try to run OCI8.new and it gives me this error
OCIError: ORA-12545: Connect failed because target host or object does not exist
I'm pretty much stuck and I'm really not sure what to do here.
TNS:
METRO=
(description=
(address_list=
(address = (protocol = TCP)(host = 127.0.0.1)(port = 1521))
)
(connect_data =
(service_name=METRO)
)
)
Database.yml :
development:
adapter: oracle_enhanced
database: metro
host: 192.168.18.55
username: metro
password: imperium
Looks like you are missing the port in database.yml file.
development:
adapter: oracle_enhanced
host: localhost
port: 1521
database: xe
username: user
password: secret

Mongoid only working in development. Throws error both is test and production

When I start my rails console as:
$ RAILS_ENV=development rails console
every thing seems to be working fine.
Mongoid is able to connect to mongodb and fetch records.
But with:
$ RAILS_ENV=test rails console
$ RAILS_ENV=production rails console
it's throwing up errors as:
Rack::File headers parameter replaces cache_control after Rack 1.5.
/usr/local/lib/ruby/gems/1.9.1/gems/mongoid-3.0.16/lib/mongoid/criteria.rb:585:in `check_for_missing_documents!': (Mongoid::Errors::DocumentNotFound)
Problem:
Document(s) not found for class Actor with id(s) 50e5259f53c205d815000001.
Summary:
When calling Actor.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): 50e5259f53c205d815000001 ... (1 total) and the following ids were not found: 50e5259f53c205d815000001.
Resolution:
Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples.
My config/mongoid.yml has the exact same set of lines for all three environments.
I'm not able to figure out why it isn't able to connect in test and production.
Update:
Mongoid.yml
development:
sessions:
default:
database: tgmd
hosts:
- localhost:27017
test:
sessions:
default:
database: tgmd
hosts:
- localhost:27017
production:
sessions:
default:
uri: <%= ENV['MONGO_URL'] %>
I temporarily solved the issue by placing a:
options:
raise_not_found_error: false
in production:
Also moved out a few scripts from jobs/ folder. It worked then.
Can anyone enlighten me on this?
I think your ENV['MONGO_URL'] contains something that is not correct.
Try to use your development database in production:
production:
sessions:
default:
database: tgmd
hosts:
- localhost:27017
if it work. Check your ENV['MONGO_URL']

Resources