I have implemented a basic HTTP server in java which I am trying to deploy to Heroku. The server behaves as expected when run on localhost, but on Heroku I get the following error in my logs:
2018-12-18T09:03:28.323430+00:00 heroku[web.1]: State changed from crashed to starting
2018-12-18T09:03:32.152747+00:00 heroku[web.1]: Starting process with command `java -jar build/http-server.jar`
2018-12-18T09:03:34.496251+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-12-18T09:03:34.517683+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2018-12-18T09:05:02.493578+00:00 heroku[web.1]: State changed from starting to crashed
2018-12-18T09:05:02.344933+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2018-12-18T09:05:02.344933+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-12-18T09:05:02.475449+00:00 heroku[web.1]: Process exited with status 137
I have set the PORT environment variable to 5000, which is what my server is currently binding to (yes, it's hard coded for now). If I change the server port to 80, for example, I can see in my logs that the server is unable to bind to that port, so I'm happy that it is binding to the correct port. My understanding of the docs is that I should just be able to set the port number that I need using the PORT environment variable.
Why, then, is Heroku unable to bind to this port? Is there some other action I should be taking, i.e. proxying from 443 to 5000?
I have set the PORT environment variable to 5000, which is what my server is currently binding to (yes, it's hard coded for now).
You've got this backwards.
The PORT environment variable is set by Heroku and your code must bind to that value. You can't hard-code the port, or choose it yourself. You must take it from the environment.
Related
When I deployed a FastAPI app to heroku
the startup event is fired twice.
Is it my problem?
The code below is not my original app, but a temporary app I made for testing.
And the Heroku was also made fresh for testing.
# Heroku logs
2022-10-18T08:37:32 app[api]: Build started by user junah.dev+1#gmail.com
2022-10-18T08:37:49 app[api]: Deploy 298098b0 by user junah.dev+1#gmail.com
2022-10-18T08:37:49 app[api]: Release v6 created by user junah.dev+1#gmail.com
2022-10-18T08:37:52 heroku[web.1]: State changed from down to starting
2022-10-18T08:37:54 heroku[web.1]: Starting process with command `uvicorn app.main:app --host=0.0.0.0 --port=${PORT:-5000}`
2022-10-18T08:37:55 app[api]: Build succeeded
2022-10-18T08:37:55.490285+00:00 app[web.1]: INFO: Uvicorn running on http://0.0.0.0:51121 (Press CTRL+C to quit)
2022-10-18T08:37:55 app[web.1]: INFO: Started parent process [4]
2022-10-18T08:37:55 app[web.1]: INFO: Started server process [11]
2022-10-18T08:37:55 app[web.1]: INFO: Waiting for application startup.
2022-10-18T08:37:55 app[web.1]: INFO: Application startup complete.
2022-10-18T08:37:55 app[web.1]: INFO: Started server process [10]
2022-10-18T08:37:55 app[web.1]: INFO: Waiting for application startup.
2022-10-18T08:37:55 app[web.1]: INFO: Application startup complete.
2022-10-18T08:37:56 heroku[web.1]: State changed from starting to up
# main.py
from fastapi import Depends, FastAPI
import uvicorn
app = FastAPI()
#app.get("/")
async def root():
return {"message": "Hello World"}
# Procfile
web: uvicorn app.main:app --host=0.0.0.0 --port=${PORT:-5000}
Uvicorn operates by running worker processes.
If you don't give it a number of processes to use via the --workers argument, it defaults to the value of the WEB_CONCURRENCY environment variable, falling back to 1 if neither is set:
--workers INTEGER Number of worker processes. Defaults to the
$WEB_CONCURRENCY environment variable if
available, or 1. Not valid with --reload.
Heroku sets a default value for the WEB_CONCURRENCY environment variable:
The WEB_CONCURRENCY environment variable is automatically set by Heroku, based on the processes’ Dyno size. This feature is intended to be a sane starting point for your application. We recommend knowing the memory requirements of your processes and setting this configuration variable accordingly.
Heroku has probably set this value to 2 based on the size of the dynos you are running. This would cause two workers to run in parallel, which is what your logs are showing:
A parent process: Started parent process [4]
And two worker processes:
Started server process [11]
Started server process [10]
You can change the value of WEB_CONCURRENCY if you wish.
If your code is malfunctioning with multiple workers that indicates a problem with your code. In that case, instead of setting this to 1, I suggest you identify why it is misbehaving and fix the problem. One common cause of this is use of global variables.
I have a node app that does a simple web scraping in real time.
Since it has no back-end feature, it doesn't listen any port and never use Express.
When I deploy this app, Heroku automatically runs some commands to build and run my app.
This is my package.json file.
"scripts": {
"develop": "nodemon --exec babel-node src",
"test": "mocha --require babel-core/register",
"build": "rimraf lib && babel src -d lib",
"start": "node lib",
"lint": "eslint src"
}
I checked the Heroku logs to see if the app is running properly but I found errors like below.
...
2020-12-27T07:24:48.000000+00:00 app[api]: Build succeeded
2020-12-27T07:25:46.564866+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-12-27T07:25:46.589773+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-12-27T07:25:46.680704+00:00 heroku[web.1]: Process exited with status 137
2020-12-27T07:25:46.732427+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-27T07:25:46.735872+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-27T07:25:51.844095+00:00 heroku[web.1]: Starting process with command `npm start`
2020-12-27T07:25:54.728760+00:00 app[web.1]:
2020-12-27T07:25:54.728776+00:00 app[web.1]: > my-node-app#0.1.0 start /app
2020-12-27T07:25:54.728777+00:00 app[web.1]: > node lib
2020-12-27T07:25:54.728777+00:00 app[web.1]:
2020-12-27T07:26:52.296540+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-12-27T07:26:52.315003+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-12-27T07:26:52.410290+00:00 heroku[web.1]: Process exited with status 137
2020-12-27T07:26:52.468187+00:00 heroku[web.1]: State changed from starting to crashed
It seems building was successful but has failed when running it.
In my opinion, Heroku tried to bind PORT but my app never listened any port, so these errors had occurred.
How can I run my app successfully with no error on Heroku in this case?
If your node.js project is a web server, you cannot remove the port. No port, no web server. Trying to make a web server without a port is like trying to make a locomotive with no railroad.
You can use the default port however. When users give browsers URLs without ports, they automatically apply the default port.
Heroku also provide the default port so you don't have to specify the port
Just deploy your app and use the url provided by the heroku to call node js application
I am trying to deploy my Spring Boot Application to Heroku but I keep getting:
2018-05-06T14:41:35.181889+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2018-05-06T14:41:35.182093+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-05-06T14:41:35.482221+00:00 heroku[web.1]: Process exited with status 137
2018-05-06T14:41:35.496155+00:00 heroku[web.1]: State changed from starting to crashed
I've seen some answers which tell me so place
server.port=${PORT:8080}
in my application property but it is still not working.
I don't see anything else what I can do and there's no further output that could hint me to the root of the problem.
Any ideas?
I know that this is a very old issue, however someone who gets this error message may pass by, here... So I'd like to share my solution to this issue:
I have been using the Maven Heroku Plugin in my Spring Boot Application
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
What happened to me is that accidently my POM-File got reformatted and therefore the contents within the <processTypes> <web>-Tag received some line-breaks.
The Heroku Maven Plugin creates a Procfile out of these contents. However the Procfile cannot deal with line-breaks in the commands.
So, after almost going crazy, I found out that a line-break caused the command to be corrupted and this caused the above error in my case.
I am trying to load a simple ruby app on heroku that periodically runs a background task using resque, which checks an email account. It works fine locally with foreman, but keeps crashing on heroku.
I think maybe the Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch comes from my while loop, which is perpetual and therefore longer than 60 seconds? Should I be using some different kind of process to launch smsnotify.rb?
Any help would be extremely appreciated!
My heroku logs:
2013-04-06T20:49:15+00:00 heroku[slugc]: Slug compilation finished
2013-04-06T20:49:18+00:00 heroku[web.1]: Starting process with command `bundle exec ruby smsnotify.rb -p 9129`
2013-04-06T20:49:21+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/multibyte.rb:26: warning: already initialized constant VALID_CHARACTER
2013-04-06T20:50:19+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2013-04-06T20:50:19+00:00 heroku[web.1]: Stopping process with SIGKILL
2013-04-06T20:50:20+00:00 heroku[web.1]: Process exited with status 137
2013-04-06T20:50:20+00:00 heroku[web.1]: State changed from starting to crashed
My Procfile:
web: bundle exec ruby smsnotify.rb -p $PORT
resque: env TERM_CHILD=1 bundle exec rake jobs:work
smsnotify.rb:
require "./email_checker"
require 'hirefire'
require 'resque'
Resque.redis = 'redis://redistogo:removed:removed/'
HireFire::Initializer.initialize!
while true do
Resque.enqueue(EmailChecker)
sleep 30
puts "Starting Email Job"
end
You aren't starting up a process that is binding to a port, so it is complaining.
You just need to change your Procfile to say 'worker' instead of 'web'
If you have a web frontend to this, then you will need a worker and a web
I created a sample app called stock portfolio manager
https://github.com/rohanmoitra/foliomanage and deployed it on heroku. But whenever I try to run heroku rake db:migrate it times out and gives the following error.
2012-10-22T22:28:35+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process
failed to bind to $PORT within 60 seconds of launch
2012-10-22T22:28:35+00:00 heroku[web.1]: Stopping process with SIGKILL
2012-10-22T22:28:36+00:00 heroku[web.1]: Process exited with status 137
2012-10-22T22:28:36+00:00 heroku[web.1]: State changed from starting to crashed
Has anyone encountered this error before? Any help would be deeply appreciated
You shouldn't do migrations on heroku boot. The latter is limited to 60 seconds. Run migrations separately as a rake task. If you really, really want to do this though, you have to work around the boot timeout (https://github.com/dblock/heroku-forward could help).