Rails 5 in production with heroku - heroku

I use rails 5 with actioncable on heroku and i have this error only in production
WebSocket connection to 'wss://adham-chatty.heroku.com/cable' failed: WebSocket opening handshake was canceled
i think because of puma
2016-01-21T23:33:56.372977+00:00 heroku[web.1]: Starting process with command `bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}`
2016-01-21T23:33:57.651242+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2016-01-21T23:33:58.721808+00:00 app[web.1]: [3] - Gracefully shutting down workers...
2016-01-21T23:33:58.873303+00:00 app[web.1]: [3] === puma shutdown: 2016-01-21 23:33:58 +0000 ===
2016-01-21T23:33:58.873305+00:00 app[web.1]: [3] - Goodbye!
2016-01-21T23:33:58.910391+00:00 app[web.1]: [3] Puma starting in cluster mode...
2016-01-21T23:33:58.910405+00:00 app[web.1]: [3] * Version 2.15.3 (ruby 2.2.3-p173), codename: Autumn Arbor Airbrush
2016-01-21T23:33:58.910407+00:00 app[web.1]: [3] * Min threads: 5, max threads: 5
2016-01-21T23:33:58.910409+00:00 app[web.1]: [3] * Environment: production
2016-01-21T23:33:58.910429+00:00 app[web.1]: [3] * Process workers: 2
2016-01-21T23:33:58.910453+00:00 app[web.1]: [3] * Preloading application
2016-01-21T23:33:59.632680+00:00 heroku[web.1]: Process exited with status 0

I just spent an evening and got my rails 5 ActionCable app working wonderfully on Heroku. I wrote up what I learned after going through a lot of hoops here: http://www.whodya.com/posts/19632. What I'd guess from looking at your error message above is, ahem, exactly the same problem I had for a bit. You're trying to use wss: to connect, but this only works if you're using SSL/HTTPS on your server. Try ws: instead, until you get HTTPS up and running. Again, my write-up is here (http://www.whodya.com/posts/19632), with my config/settings/etc.
-John

Related

Heroku: This site can’t be reached

My heroku app cannot be accessed after a build. The logs show that the web server node and worker node both are listening.
It's a flask app run by gunicorn and it has 2 addons - newrelic and redistogo.
Error:
This site can’t be reached.
appname.herokuapp.com’s server IP address could not be found.
DNS_PROBE_FINISHED_NXDOMAIN
Logs:
```2020-02-05T16:24:31.556201+00:00 heroku[worker.1]: Starting process with command `python worker.py`
2020-02-05T16:24:32.278863+00:00 heroku[worker.1]: State changed from starting to up
2020-02-05T16:24:33.363132+00:00 app[worker.1]: 16:24:33 RQ worker started, version 0.5.1
2020-02-05T16:24:33.364484+00:00 app[worker.1]: 16:24:33
2020-02-05T16:24:33.364574+00:00 app[worker.1]: 16:24:33 *** Listening on high, default, low...
2020-02-05T16:24:35.295791+00:00 heroku[web.1]: Starting process with command `newrelic-admin run-program gunicorn app:server`
2020-02-05T16:24:41.159117+00:00 heroku[web.1]: State changed from starting to up
2020-02-05T16:24:40.959907+00:00 app[web.1]: [2020-02-05 16:24:40 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-02-05T16:24:40.961836+00:00 app[web.1]: [2020-02-05 16:24:40 +0000] [4] [INFO] Listening at: http://0.0.0.0:21126 (4)
2020-02-05T16:24:40.962097+00:00 app[web.1]: [2020-02-05 16:24:40 +0000] [4] [INFO] Using worker: sync
2020-02-05T16:24:40.971809+00:00 app[web.1]: [2020-02-05 16:24:40 +0000] [12] [INFO] Booting worker with pid: 12
2020-02-05T16:24:41.143051+00:00 app[web.1]: [2020-02-05 16:24:41 +0000] [20] [INFO] Booting worker with pid: 20```
EDIT:
Procfile:
web: newrelic-admin run-program gunicorn app:server
worker: python worker.py
Worker:
import os
import redis
from rq import Worker, Queue, Connection
listen = ['high', 'default', 'low']
redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')
conn = redis.from_url(redis_url)
if __name__ == '__main__':
with Connection(conn):
worker = Worker(list(map(Queue, listen)))
worker.work()
The app is accessible now. It seems to be downtime with Heroku. Although they haven't reported this in their status page.

RubyMine: Termination timed out worker

I´ve a problem to debug my application in docker. My setup is correct I think because without debugger everything works fine.
Ports
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
- "1234:1234"
- "26162:26162"
- "26168:26168"
The error: (The site is not responding)
Fast Debugger (ruby-debug-ide 0.7.0, debase 0.2.4.1, file filtering is supported) listens on 0.0.0.0:1234
=> Booting Puma
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
[8] Puma starting in cluster mode...
[8] * Version 4.0.1 (ruby 2.6.2-p47), codename: 4 Fast 4 Furious
[8] * Min threads: 5, max threads: 5
[8] * Environment: development
[8] * Process workers: 2
[8] * Preloading application
[8] * Listening on tcp://0.0.0.0:3000
[8] Use Ctrl-C to stop
[8] ! Terminating timed out worker: 16
[8] ! Terminating timed out worker: 18
[8] ! Terminating timed out worker: 20
[8] ! Terminating timed out worker: 21
[8] ! Terminating timed out worker: 24
[8] ! Terminating timed out worker: 25
[8] ! Terminating timed out worker: 28
[8] ! Terminating timed out worker: 29
I just figured it out.
My solution is set WEB_CONCURRENCY to 0 (config/puma.rb)
workers ENV.fetch("WEB_CONCURRENCY") { 0 }
For the production system I change the value in the .env file.
WEB_CONCURRENCY=2
Source:
* https://github.com/JetBrains/sample_rails_app/blob/master/config/puma.rb
# Note that workers are not supported for JRuby or Windows
#workers ENV.fetch("WEB_CONCURRENCY") { 2 }

Deploying clojure web-app on Heroku, $PORT binding

I wrote a 20-minute web-service that I needed quickly deployed, so I thought of Heroku. I went through their example, added a Procfile as per the documentation:
web: java $JVM_OPTS -cp target/random-pairs.jar Clojure.main -m random-pairs.system
The server is just jetty wrapped in a Component/Lifecycle interface implementation, so I added calls that read PORT/HOST from Heroku ENV, also didn't take long:
(defn new []
(let [host (or (System/getenv "HOST") "localhost")
port (or (Integer. (System/getenv "PORT")) 8080)]
(map->Server {:host host :port port :server nil :database nil})))
Then I pushed to heroku branch and was very happy to see that it builds:
remote: -----> Clojure (Leiningen 2) app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Using cached Leiningen 2.7.1
remote: Writing: lein script
remote: -----> Building with Leiningen
remote: Running: lein uberjar
remote: Compiling random-pairs.api
remote: Compiling random-pairs.routing
remote: Compiling random-pairs.server
remote: Compiling random-pairs.system
remote: Compiling random-pairs.utils
remote: Created /tmp/build_39db3b5354727cb980092a4caa080664/target/random-pairs-0.1.0-SNAPSHOT.jar
remote: Created /tmp/build_39db3b5354727cb980092a4caa080664/target/random-pairs.jar
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 70.5M
remote: -----> Launching...
I peeked at the logs to confirm:
2017-09-27T10:11:43.214499+00:00 heroku[web.1]: Starting process with command `java $JVM_OPTS -cp target/random-pairs.jar clojure.main -m random-pairs.system`
2017-09-27T10:11:46.312843+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2017-09-27T10:11:46.316262+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -Dfile.encoding=UTF-8
2017-09-27T10:11:49.562990+00:00 app[web.1]: 2017-09-27 10:11:49.559 INFO default org.eclipse.jetty.util.log - Logging initialized #3234ms
2017-09-27T10:11:50.401779+00:00 app[web.1]: 2017-09-27 10:11:50.401 INFO default random-pairs.system - :random-pairs.system/create-system Creating system
2017-09-27T10:11:50.404459+00:00 app[web.1]: 2017-09-27 10:11:50.404 INFO default random-pairs.system - :random-pairs.system/start Starting the application
2017-09-27T10:11:50.409370+00:00 app[web.1]: 2017-09-27 10:11:50.409 INFO default random-pairs.server - :random-pairs.server/server-start Starting Server component host: localhost port: 15701
2017-09-27T10:11:50.435805+00:00 app[web.1]: 2017-09-27 10:11:50.435 INFO default org.eclipse.jetty.server.Server - jetty-9.2.z-SNAPSHOT
2017-09-27T10:11:50.478304+00:00 app[web.1]: 2017-09-27 10:11:50.477 INFO default o.e.jetty.server.ServerConnector - Started ServerConnector#1a1f79ce{HTTP/1.1}{localhost:15701}
2017-09-27T10:11:50.478742+00:00 app[web.1]: 2017-09-27 10:11:50.478 INFO default org.eclipse.jetty.server.Server - Started #4162ms
2017-09-27T10:11:50.479247+00:00 app[web.1]: 2017-09-27 10:11:50.479 INFO default random-pairs.system - :random-pairs.system/main Application fully functional
Nice, Heroku seems neat.
So I went on to send some requests to test everything works OK. Only that it didn't. I looked once again at the logs only to see:
2017-09-27T10:13:48.345516+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-09-27T10:13:48.345575+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-09-27T10:13:48.488069+00:00 heroku[web.1]: State changed from starting to crashed
2017-09-27T10:13:48.476415+00:00 heroku[web.1]: Process exited with status 137
What is this in the name of Zeus? Failed to bind to $PORT? I clearly see in the logs Jetty picked up the port and the system went online?
I know what happens - it's classic IP4/IP6, "localhost" resolves to ip6 address on heroku cloud machine. Putting 0.0.0.0 (or presumably also specifying no host as suggested in the comment) solves the problem.

Gibbon failed to open tcp connection on Heroku

Going through Daniel Kehoe's Learn Ruby on Rails book. Have tutorial successfully posting to MailChimp list in development. Pushed to heroku, and tested. When submitting email address to join newsletter, get error in logs -
2016-09-08T19:54:14.872341+00:00 app[web.1]: Completed 500 Internal
Server Error in 12ms (ActiveRecord: 0.0ms)
2016-09-08T19:54:14.872876+00:00 app[web.1]:
2016-09-08T19:54:14.872878+00:00 app[web.1]: Gibbon::MailChimpError
(Failed to open TCP connection to key.api.mailchimp.com:443
(getaddrinfo: Name or service not known) #title=nil, #detail=nil,
#body=nil, #raw_body=nil, #status_code=nil):
2016-09-08T19:54:14.872879+00:00 app[web.1]:
app/models/visitor.rb:10:in subscribe'
2016-09-08T19:54:14.872880+00:00 app[web.1]:
app/controllers/visitors_controller.rb:10:in `create'
Suggestions on how to troubleshoot would be appreciated.

Heroku fails to scale, no status, log shows 413

Could anyone please help with Heroku's guide of "getting started with java":
https://devcenter.heroku.com/articles/getting-started-with-java
It works fine with scale=1
But it fails when I try to scale up, eg:
heroku ps:scale web=2 --app myap
This responds "internal server error" and asks to run "heroku status".
However "heroku status" just says "no knows issues at this time".
And "heroku:logs" doesn't give much info, except perhaps some "413" error:
2013-12-19T06:42:53+00:00 heroku[slug-compiler]: Slug compilation finished
2013-12-19T06:42:53.947859+00:00 heroku[web.1]: State changed from up to starting
2013-12-19T06:42:57.590970+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2013-12-19T06:42:58.225911+00:00 heroku[web.1]: Starting process with command `java -cp target/classes:target/dependency/* HelloWorld`
2013-12-19T06:42:59.363034+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Djava.rmi.server.useCodebaseOnly=true -Djava.rmi.server.useCodebaseOnly=true
2013-12-19T06:42:59.677493+00:00 app[web.1]: 2013-12-19 06:42:59.675:INFO:oejs.Server:jetty-7.6.0.v20120127
2013-12-19T06:42:59.752285+00:00 app[web.1]: 2013-12-19 06:42:59.751:INFO:oejsh.
ContextHandler:started o.e.j.s.ServletContextHandler{/,null}
2013-12-19T06:42:59.795692+00:00 app[web.1]: 2013-12-19 06:42:59.787:INFO:oejs.A
bstractConnector:Started SelectChannelConnector#0.0.0.0:37683
2013-12-19T06:42:59.936719+00:00 heroku[web.1]: Process exited with status 143
2013-12-19T06:43:00.226719+00:00 heroku[web.1]: State changed from starting to u
Help would be appreciated,
thanks very much

Resources