heroku keep killing idle connections (websocket) - heroku

Some log from heroku:
2022-10-16T05:19:03.088622+00:00 heroku[router]: at=error code=H15 desc="Idle connection" method=GET path="/api/v1/content/ws/RgPx8znal7AJb
2022-10-16T05:19:03.065493+00:00 app[web.1]: time="2022-10-16T05:19:03Z" level=info msg="error - on read: websocket: close 1006 (abnormal closure): unexpected EOF"
2022-10-16T05:20:57.758379+00:00 app[web.1]: time="2022-10-16T05:20:57Z" level=info msg="cleanup client, id = 'wscid-ee670cc5-4100-49d6-9857-8284d93a6d33'"
2022-10-16T05:20:57.758505+00:00 app[web.1]: time="2022-10-16T05:20:57Z" level=info msg="close msg received: &{418 close}"
Seems heroku will kill the websocket connection if there is no msg for a while.
Questions:
If I want to keep the connection alive:
Should I send ping/pong msg to keep the connection alive?
Or, there are other ways to do that (e.g upgrade my account paid plan?) ?
BTW:
If I deploy it on bare linux, the websocket connection never auto close.
I do have auto connect from the client side, but that's even more expensive, and not good for user experience I think.
Update
Seems heroku router will kill the idle connection after 55 seconds.

Related

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch when building a streamlit web app on Heroku

I was building a web application on Heroku and encountered this issue:
2020-10-24T03:56:57.857273+00:00 app[web.1]: You can now view your Streamlit app in your browser.
2020-10-24T03:56:57.857320+00:00 app[web.1]:
2020-10-24T03:56:57.857675+00:00 app[web.1]: Network URL: http://172.17.131.6:8501
2020-10-24T03:56:57.857819+00:00 app[web.1]: External URL: http://34.202.9.122:8501
2020-10-24T03:56:57.857932+00:00 app[web.1]:
2020-10-24T03:56:59.458188+00:00 app[web.1]: 2020-10-24 03:56:59.458 Generating new fontManager, this may take some time...
2020-10-24T03:57:41.000000+00:00 app[api]: Build succeeded
2020-10-24T03:57:52.127634+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-10-24T03:57:52.147741+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-10-24T03:57:52.252583+00:00 heroku[web.1]: Process exited with status 137
2020-10-24T03:57:52.301275+00:00 heroku[web.1]: State changed from starting to crashed
2020-10-24T03:57:53.705631+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=okc-thunder-rebounds.herokuapp.com request_id=a90bb347-f583-4bec-8a6c-37bfea93908e fwd="71.232.30.113" dyno= connect= service= status=503 bytes= protocol=https
My setup.sh is like:
mkdir -p ~/.streamlit/
echo "\
[general]\n\
email = \"qemail#domain.com\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml
And my Procfile is like:
web: sh setup.sh && streamlit run rebound_app.py
Where does it go wrong?
The application must bind to the port provided by Heroku via the $PORT env variable. This is a requirement for every Web Dyno.
You need to pass the $PORT to streamlit
echo PORT $PORT
streamlit run --server.port $PORT rebound_app.py

Getting sporadic "http: proxy error: read tcp: i/o timeout" on Heroku [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm getting this error sporadically on Heroku:
Proxy service:
Dec 27 14:53:05 betalo-turnpike-production app/web.2: { [...] }
Dec 27 14:53:08 my-proxy app/web.2: {
"level":"error",
"ts":"2018-12-27T14:53:07.771Z",
"caller":"httputil/reverseproxy.go:393","msg":"http: proxy error: read tcp [REDACTED]->[REDACTED]: i/o timeout",
"stacktrace":"log.(*Logger).Output
/app/tmp/cache/go1.11.4/go/src/log/log.go:172
log.(*Logger).Printf
/app/tmp/cache/go1.11.4/go/src/log/log.go:179
net/http/httputil.(*ReverseProxy).logf
/app/tmp/cache/go1.11.4/go/src/net/http/httputil/reverseproxy.go:393
net/http/httputil.(*ReverseProxy).defaultErrorHandler
/app/tmp/cache/go1.11.4/go/src/net/http/httputil/reverseproxy.go:158
net/http/httputil.(*ReverseProxy).defaultErrorHandler-fm
/app/tmp/cache/go1.11.4/go/src/net/http/httputil/reverseproxy.go:166
net/http/httputil.(*ReverseProxy).ServeHTTP
/app/tmp/cache/go1.11.4/go/src/net/http/httputil/reverseproxy.go:234
net/http/httputil.(*ReverseProxy).ServeHTTP-fm
[...]
net/http.HandlerFunc.ServeHTTP
/app/tmp/cache/go1.11.4/go/src/net/http/server.go:1964
net/http.serverHandler.ServeHTTP
/app/tmp/cache/go1.11.4/go/src/net/http/server.go:2741
net/http.(*conn).serve
/app/tmp/cache/go1.11.4/go/src/net/http/server.go:1847"}
Dec 27 14:53:08 my-proxy app/web.2: { [...] "status":502}
Dec 27 14:53:09 my-proxy heroku/router: sock=backend at=error code=H18 desc="Server Request Interrupted" [...] dyno=web.2 connect=0ms service=4453ms status=503 protocol=https
Called service:
Dec 27 14:53:05 my-service app/web.1: { [...] }
Dec 27 14:53:08 my-service app/web.1: { [...] "status":400}
Dec 27 14:53:08 my-service heroku/router: sock=client at=warning code=H27 desc="Client Request Interrupted" [...] dyno=web.1 connect=1ms service=2995ms status=499 bytes=0 protocol=https
Anyone knows what is wrong?
externally, my proxy returns 502 (upstream gone away)
my proxy talks to my service which returns 400 (client error)
the router layer returns 499 (client closed request)
what is happening is that the external caller is dropping the connection while the "my service" is preparing a result to go back on the connection
to "my proxy". This means that the socket drops from the "my proxy" side.
The router at the my service side logs a 499 and so the app logs a 400
There is nothing wrong with your code. The external clients using your web service are dropping their connections early and this is how the application responds in logs

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 Go app crashing

Following this tutorial, everything works locally. After I deploy my app to Heroku and visit the app on the browser I get a 503 Error and the message:
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
The logs say:
2015-09-08T16:31:53.976824+00:00 heroku[web.1]: State changed from crashed to starting
2015-09-08T16:31:56.174376+00:00 heroku[web.1]: Starting process with command `mywebsite`
2015-09-08T16:31:59.312461+00:00 app[web.1]: Listening on port: 39461
2015-09-08T16:32:56.471550+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2015-09-08T16:32:56.471550+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-09-08T16:32:57.390752+00:00 heroku[web.1]: Process exited with status 137
2015-09-08T16:32:57.404208+00:00 heroku[web.1]: State changed from starting to crashed
2015-09-08T16:32:57.645135+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-eyrie-6897.herokuapp.com request_id=ec26... fwd="xx.xxx.xxx.xxx" dyno= connect= service= status=503 bytes=
2015-09-08T16:32:58.233774+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-eyrie-6897.herokuapp.com request_id=ef40...fwd="xx.xxx.xxx.xxx" dyno= connect= service= status=503 bytes=
I understand what the errors are, but how can such a tiny tutorial app be causing a boot timeout (R10)?
How can I debug this better and fix the app so it runs?
When you deploy an app through heroku, it does not allow you to specify the port number.
In other words, you can not specify your web service's port number as 8000 or something else, heroku decides the port number in runtime.
so, you can not use the following code:
log.Fatal(http.ListenAndServe(":8000", router))
What you can do is, getting the runtime port of heroku.
In short, just use the following code:
log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router))
Your app needs to listen to all network connections. If it only listens on localhost, heroku's process watcher will not be able to detect that you bound the port, nor send requests to your app.
That means instead of:
http.ListenAndServe("127.0.0.1:"+port, nil)
You need to call:
http.ListenAndServe(":"+port, nil)
See also the heroku getting started with Go app: https://github.com/heroku/go-getting-started/blob/master/cmd/go-getting-started/main.go#L27

We're sorry, but something went wrong Heroku

Don't start app at Heroku.
Migrate I was do, but it don`t work anyway... Please help my anyone
2015-07-17T08:27:11.996879+00:00 app[web.1]: => Booting Puma
2015-07-17T08:27:11.996906+00:00 app[web.1]: => Rails 4.2.1 application starting in production on http://0.0.0.0:15906
2015-07-17T08:27:11.996909+00:00 app[web.1]: => Run `rails server -h for more startup options
2015-07-17T08:27:11.996910+00:00 app[web.1]: => Ctrl-C to shutdown server
2015-07-17T08:27:16.038259+00:00 heroku[web.1]: State changed from starting to up
2015-07-17T08:27:15.924000+00:00 app[web.1]: Puma 2.11.3 starting...
2015-07-17T08:27:15.924095+00:00 app[web.1]: * Min threads: 0, max threads: 16
2015-07-17T08:27:15.924199+00:00 app[web.1]: * Environment: production
2015-07-17T08:27:15.924281+00:00 app[web.1]: * Listening on tcp://0.0.0.0:15906
2015-07-17T08:27:18.702571+00:00 heroku[router]: at=info method=GET path="/" host=shrouded-eyrie-5960.herokuapp.com request_id=7976700d-bee7-4e6f-b20a-67d60a5d5e8a fwd="176.104.8.251" dyno=web.1 connect=1ms service=210ms status=500 bytes=1669
2015-07-17T08:27:18.819798+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=shrouded-eyrie-5960.herokuapp.com request_id=23341143-bd39-46ed-a48a-736533558ccd fwd="176.104.8.251" dyno=web.1 connect=1ms service=2ms status=200 bytes=143`
This error comes from your app's code. However, your app is sending it's logs to the local filesystem, which means you don't see the exception in heroku logs.
You would need to configure your app to send logs to STDOUT or STDERR to be able to see them.
You can add the rails_12factor gem to your app, which will change your configuration to do just that.
Once you have added this gem to your app and redeployed it, the raised exception should show in your logs and you can fix in your app's code.

Resources