I've been trying everything I can find online, and nothing is working. Hoping some fresh eyes will see the issue. This is my first time using ActionCable, and everything works great locally, but when pushing to heroku. my logs do not show any actioncable subscriptions like my dev server:
[ActionCable] [email#email.com] MsgsChannel is streaming from msg_channel_34
and when sending a message, I do see [ActionCable] Broadcasting to msg_channel_34: but they are not appending, which I'm guessing means that the received method is not being accessed/called?
I do notice on heroku's logs it says Listening on tcp://0.0.0.0:5000 where as dev it is listening at localhost:3000. Should I be pointnig towards my heroku app somehow?
Here are the relevant configuration files:
Procfile:
web: bundle exec puma -p 5000 ./config.ru
actioncable: bundle exec puma -p 28080 cable/config.ru
redis: redis-server
***Thanks to the comment below, I am also trying. Still not working, but I can see that the port it's listening to is changing, making me believe it has something to do with the configuration? :
web: bundle exec puma -p $PORT ./config.ru
actioncable: bundle exec puma -p $PORT cable/config.ru
redis: redis-server
/cable/config.ru
require ::File.expand_path('../../config/environment', __FILE__)
Rails.application.eager_load!
ActionCable.server.config.allowed_request_origins = ["http://localhost:3000"]
run ActionCable.server
config/environments/development.rb
config.action_cable.allowed_request_origins = ['localhost:3000']
config.action_cable.url = "ws://localhost:3000/cable"
config/environments/production.rb
config.web_socket_server_url = "wss://app-name.herokuapp.com/cable"
config.action_cable.allowed_request_origins = ['https://app-name.herokuapp.com', 'http://app-name.herokuapp.com']
config/cable.yml
local: &local
adapter: async
:url: redis://localhost:6379
:host: localhost
:port: 6379
:timeout: 1
:inline: true
development: *local
test: *local
production:
:url: redis:<%= ENV["REDISTOGO_URL"] %>
adapter: redis
<%= ENV["REDISTOGO_URL"] %> is set, confirmed by running heroku config
routes.rb
mount ActionCable.server => '/cable'
Why is this working on dev, but not on heroku? I've been reading for hours, but can not figure it out. Thank you!!
UPDATE:
heroku logs:
2017-01-25T20:32:57.329656+00:00 heroku[web.1]: Starting process with command `bundle exec puma -p 5000 ./config.ru`
2017-01-25T20:32:59.600554+00:00 app[web.1]: Puma starting in single mode...
2017-01-25T20:32:59.600574+00:00 app[web.1]: * Version 3.6.2 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
2017-01-25T20:32:59.600575+00:00 app[web.1]: * Min threads: 0, max threads: 16
2017-01-25T20:32:59.600577+00:00 app[web.1]: * Environment: production
2017-01-25T20:33:02.375128+00:00 app[web.1]: profile controller
2017-01-25T20:33:02.588653+00:00 app[web.1]: Use Ctrl-C to stop
2017-01-25T20:33:02.588446+00:00 app[web.1]: * Listening on tcp://0.0.0.0:5000
2017-01-25T20:33:17.681469+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-01-25T20:33:17.681469+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-01-25T20:33:17.862118+00:00 heroku[web.1]: Process exited with status 137
2017-01-25T20:33:57.501746+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-01-25T20:33:57.501908+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-01-25T20:33:57.630071+00:00 heroku[web.1]: Process exited with status 137
2017-01-25T20:33:57.642753+00:00 heroku[web.1]: State changed from starting to crashed
The issue was my host is the heroku app, but the requests were coming from the custom domain.
To solve:
heroku config:set RAILS_HOST "http://www.example.com"
And then in production.rb:
config.action_cable.url = "wss://#{ENV['RAILS_HOST']}/cable"
Is your app name literally app-name? I suspect not. Odds are pretty good that these values...
config.web_socket_server_url = "wss://app-name.herokuapp.com/cable"
config.action_cable.allowed_request_origins = ['https://app-name.herokuapp.com', 'http://app-name.herokuapp.com']
Need to be updated to use the actual public-facing URL you intend to connect to.
Your procfile suggests that you run puma with cable/cable.ru on port 28080. Also - file cable/config.ru shouldn't contain this line:
ActionCable.server.config.allowed_request_origins = ["http://localhost:3000"]
You already configured this in config/environment/*.rb
I had the same issue, and found the answer I needed here: redis gem 4+ incompatibility "Specified 'redis' for Action Cable pubsub adapter, but the gem is not loaded". Once I downgraded my redis to 3.1.0, worked perfectly.
Related
I have a new, Rails 6 app that I'm trying to deploy to Heroku.
Judging from the deploy log and the logs I'm getting with heroku logs --tail everything seems to work, but when I go to the deployed, herokuapp.com domain, I get the 'No such app' screen.
Here is the latest logs:
2021-11-19T13:45:11.000000+00:00 app[api]: Build succeeded
2021-11-19T13:45:11.060793+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb`
2021-11-19T13:45:12.126085+00:00 app[web.1]: [4] Puma starting in cluster mode...
2021-11-19T13:45:12.126103+00:00 app[web.1]: [4] * Puma version: 5.5.2 (ruby 3.0.2-p107) ("Zawgyi")
2021-11-19T13:45:12.126103+00:00 app[web.1]: [4] * Min threads: 5
2021-11-19T13:45:12.126104+00:00 app[web.1]: [4] * Max threads: 5
2021-11-19T13:45:12.126104+00:00 app[web.1]: [4] * Environment: production
2021-11-19T13:45:12.126104+00:00 app[web.1]: [4] * Master PID: 4
2021-11-19T13:45:12.126104+00:00 app[web.1]: [4] * Workers: 2
2021-11-19T13:45:12.126127+00:00 app[web.1]: [4] * Restarts: (✔) hot (✖) phased
2021-11-19T13:45:12.126133+00:00 app[web.1]: [4] * Preloading application
2021-11-19T13:45:13.203269+00:00 app[web.1]: [4] * Listening on http://0.0.0.0:54150
2021-11-19T13:45:13.203334+00:00 app[web.1]: [4] Use Ctrl-C to stop
2021-11-19T13:45:13.207647+00:00 app[web.1]: [4] - Worker 0 (PID: 7) booted in 0.0s, phase: 0
2021-11-19T13:45:13.209455+00:00 app[web.1]: [4] - Worker 1 (PID: 9) booted in 0.0s, phase: 0
2021-11-19T13:45:13.336382+00:00 heroku[web.1]: State changed from starting to up
And here's the puma config:
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
Which is the one recommended by Heroku in their documentation.
The Procfile is a simple one-liner:
web: bundle exec puma -C config/puma.rb
I also tried the heroku configuration by running PORT=3000 heroku local on my machine and it works wonderfully, but not on Heroku's platform :(
I'm using Rails 6.1.4.1 and ruby 3.0.2
Can you point me at where I could try to find the root of the problem?
Thank you,
Balint
This seems to have been a transient issue. When I came back to the problem a few hours later, it just worked without me having to change anything.
I have a Rails API Backend with a React front end that is deployed to Heroku. When I try to load a page that makes a call to the API, it hangs and then finally gives this error in the console:
GET https://MYAPP.herokuapp.com:3001/auth/refresh_token net::ERR_TIMED_OUT
When I look at the logs while the application is starting up, it looks as though I'm setting the port to 3001 which is what I want but it looks as those puma is listening on a different port number:
2020-10-01T04:28:51.720203+00:00 heroku[web.1]: Starting process with command `bundle exec puma -t 5:5 -p ${PORT:-3001} -e ${RACK_ENV:-production}`
2020-10-01T04:28:55.321298+00:00 app[web.1]: Puma starting in single mode...
2020-10-01T04:28:55.321325+00:00 app[web.1]: * Version 4.3.5 (ruby 2.6.6-p146), codename: Mysterious Traveller
2020-10-01T04:28:55.321326+00:00 app[web.1]: * Min threads: 5, max threads: 5
2020-10-01T04:28:55.321326+00:00 app[web.1]: * Environment: production
2020-10-01T04:29:04.625683+00:00 app[web.1]: * Listening on tcp://0.0.0.0:55912
Should I be configuring my fetches to use this URL instead?: https://MYAPP.herokuapp.com/auth/refresh_token
Basically, what I'm asking is: Based on this log information where is my Rails API listening if my React application is listening at: https://MYAPP.herokuapp.com?
Rails 5.2
redis 4.0.1
sidekiq 5.1.3
RedisToGo on Heroku
Proc File:
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -e production -C config/sidekiq.yml
sidekiq.yml
development:
:concurrency: 5
production:
:concurrency: 6
:queues:
- default
config/initialize/sidekiq.rb
if Rails.env.production?
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDISTOGO_URL'] || ENV['REDIS_URL'], size: 1 }
end
Sidekiq.configure_server do |config|
pool_size = ENV['SIDEKIQ_DB_POOL'] || (Sidekiq.options[:concurrency] + 2)
config.redis = { url: ENV['REDISTOGO_URL'] || ENV['REDIS_URL'], size: pool_size }
Rails.application.config.after_initialize do
Rails.logger.info("DB Connection Pool size for Sidekiq Server before disconnect is: #{ActiveRecord::Base.connection.pool.instance_variable_get('#size')}")
ActiveRecord::Base.connection_pool.disconnect!
ActiveSupport.on_load(:active_record) do
db_config = Rails.application.config.database_configuration[Rails.env]
db_config['reaping_frequency'] = ENV['DATABASE_REAP_FREQ'] || 10 # seconds
db_config['pool'] = pool_size
ActiveRecord::Base.establish_connection(db_config)
Rails.logger.info("DB Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('#size')}")
end
end
end
end
I have no idea why the job is stuck in the queue. The job works on my local in development.
Any assistance appreciated.
Update!
As per the comment here is the output of heroku ps:
=== web (Free): bundle exec puma -C config/puma.rb (1)
web.1: up 2018/06/15 18:49:56 +0700 (~ 5s ago)
=== worker (Free): bundle exec sidekiq -q default (1)
worker.1: crashed 2018/06/15 18:49:51 +0700 (~ 10s ago)
Seems a worker crashed for some reason.
Heroku logs:
2018-06-15T11:56:00.301716+00:00 app[web.1]: [4] Puma starting in cluster mode...
2018-06-15T11:56:00.301740+00:00 app[web.1]: [4] * Version 3.11.2 (ruby 2.4.1-p111), codename: Love Song
2018-06-15T11:56:00.301760+00:00 app[web.1]: [4] * Min threads: 5, max threads: 5
2018-06-15T11:56:00.301794+00:00 app[web.1]: [4] * Environment: production
2018-06-15T11:56:00.301801+00:00 app[web.1]: [4] * Process workers: 2
2018-06-15T11:56:00.301838+00:00 app[web.1]: [4] * Preloading application
2018-06-15T11:56:01.249511+00:00 app[worker.1]: DB Connection Pool size for Sidekiq Server before disconnect is: 5
2018-06-15T11:56:01.252654+00:00 app[worker.1]: could not connect to server: No such file or directory
2018-06-15T11:56:01.252657+00:00 app[worker.1]: Is the server running locally and accepting
2018-06-15T11:56:01.252659+00:00 app[worker.1]: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
After talking with tech support at Heroku it turns out that I needed to change the way I had my db yaml file coded.
I changed it to the following:
production:
url: <%= ENV['DATABASE_URL'] %>
That seem to solve the issue.
Install Heroku Postgres as an addon and then add the environment variables to your project and everything should work fine. - https://elements.heroku.com/addons/heroku-postgresql
I haven't been able to reliably reproduce this issue, so I'll describe what's happening and hope one of you wise puma kids out there can help me out.
I always stop and start puma at the end of my deploy process. I run pumactl -F <config_path> stop, which works, and then the command puma -q -d -e staging -C <config_path>, which sometimes (not always) causes the following error:
[12802] Puma starting in cluster mode...
[12802] * Version 2.11.3 (ruby 2.1.2-p95), codename: Intrepid Squirrel
[12802] * Min threads: 2, max threads: 4
[12802] * Environment: staging
[12802] * Process workers: 2
[12802] * Phased restart available
[12802] * Listening on unix:///<app_dir>/tmp/puma/sockets/puma.sock
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/binder.rb:284:in `add_unix_listener': There is already a server bound to: <app_dir>/tmp/puma/sockets/puma.sock (RuntimeError)
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/binder.rb:124:in `block in parse'
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/binder.rb:82:in `each'
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/binder.rb:82:in `parse'
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/cluster.rb:325:in `run'
<ruby_path>/2.1.0/gems/puma-2.11.3/lib/puma/cli.rb:216:in `run'
<ruby_path>/2.1.0/gems/puma-2.11.3/bin/puma:10:in `<top (required)>'
<ruby_path>/2.1.0/bin/puma:23:in `load'
<ruby_path>/2.1.0/bin/puma:23:in `<main>'
If I try to run the same puma start command again afterwards, it works.
Here's my puma config:
#!/usr/bin/env puma
directory "<app_dir>/current"
rackup "<app_dir>/current/config.ru"
environment "staging"
pidfile "<app_dir>/tmp/puma/pid"
state_path "<app_dir>/tmp/puma/state"
activate_control_app "<app_dir>/tmp/puma/sockets/pumactl.sock"
stdout_redirect "<app_dir>/shared/log/puma.error.log", "<app_dir>/shared/log/puma.access.log", true
threads 2,4
bind "unix:///<app_dir>/tmp/puma/sockets/puma.sock"
workers 2
My questions:
How can I reproduce this error?
How can I fix it? Is this a problem with puma or with my configuration?
Instead of running both commands...
pumactl -F <config_path> stop
puma -q -d -e <env> -C <config_path>
just use the restart command:
pumactl -F <config_path> restart
Explanation
The puma README has a section on Restarting that contains no mention of calling the stop and start commands one after the other. Because that use case is unsupported, using the established method to restart the puma server will most likely clear up this issue.
Note
I was unable to consistently reproduce this puma error, so I can't 100% confirm that using pumactl restart fixes the problem. (Even though puma's lack of support for pumactl stop followed by puma implies that it does.) If someone continues to have this issue while using the supported pumactl restart, please let me know so I can modify this answer.
I keep getting this in the heroku log:
14-10-30T12:59:51+00:00 heroku[slug-compiler]: Slug compilation finished
2014-10-30T12:59:51.608050+00:00 heroku[web.1]: State changed from crashed to starting
2014-10-30T13:00:00.705131+00:00 heroku[web.1]: Starting process with command `bundle exec unicorn -p 35211 -c ./co
nfig/unicorn.rb`
2014-10-30T13:00:03.661476+00:00 app[web.1]: I, [2014-10-30T13:00:03.661285 #2] INFO -- : Refreshing Gem list
2014-10-30T13:00:15.728226+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2014-10-30T13:00:21.655877+00:00 heroku[web.1]: State changed from starting to crashed
checked pretty much everything all answers in google.
db:setup worked
db:migrate worked
config.assets.initialize_on_precompile = false is set
it's not only heroku, I also get the same error in local production environment:
Macs-MacBook-Pro:v1 mac$ RAILS_ENV=production rails s
=> Booting WEBrick
=> Rails 3.2.13 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Connecting to database specified by database.yml
Exiting
here is database.yml
production:
adapter: postgresql
host: 127.0.0.1
port: 5432
encoding: unicode
database: s1_development
pool: 5
username: postgres
password: password
don't have any problems with local dev environment :(
WHat else can I do ? or how to find the problem ?