Running Dropwizard app on Heroku: R10 failed to bind to $PORT - java

I was recently pointed in the direction of dropwizard and heroku for the relatively easy creation and deployment of restFUL webservices.
Having followed the getting started tutorial at http://dropwizard.readthedocs.org/en/latest/getting-started.html I soon had a simple Hello World service running on my localhost, no problems at all.
Moving onto trying to deploy this on Heroku I have hit an issue. On deploying the app to heroku, I get an error
2014-08-14T11:34:59.869067+00:00 heroku[web.1]: State changed from starting to crashed
2014-08-14T11:34:59.070364+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web
process failed to bind to $PORT within 60 seconds of launch
2014-08-14T11:34:59.070573+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-08-14T11:34:59.857478+00:00 heroku[web.1]: Process exited with status 137
My Procfile looks like....
web java $JAVA_OPTS -D.http.port=$PORT -jar target/exampleMavenProject-0.0.1-SNAPSHOT.jar server hello-world.yml
Which is exactly the same as the command line code to run the app on the local host, with the exception of
$JAVA_OPTS -D.http.port=$PORT
$JAVA_OPTS is definied within the herkou app config variables; and from my understanding $PORT can't be overridden.
And the hello-world.yml doesn't have any extra configuration variables in it other than those required for the dropwizard example
template: Hello, %s!
defaultName: Stranger
Does anyone have any suggestions as to why this doesn't work?
Thanks.

Dropwizard 0.7.x has changed their server configurations; in particular, http.port does not work anymore.
Instead, you should be using server.connector.port for your procfile/.yml files. Here's an example:
Procfile
web: java $JAVA_OPTS -Ddw.server.connector.port=$PORT -jar target/pos-tagger-1.0-SNAPSHOT.jar server src/main/resources/POSTagger.yml
POSTagger.yml
server:
type: simple
applicationContextPath: /
adminContextPath: /admin
connector:
type: http
port: 8080
If you want to see a full, working heroku example using 0.7.x, check out: https://github.com/xinranxiao/POSTagger

Update for Dropwizard 1.0 with Gradle:
Procfile
web: java $JAVA_OPTS -Ddw.server.applicationConnectors[0].port='$PORT' -jar build/libs/yourJar-1.0-all.jar server config-production.yml
config-production.yml
server:
registerDefaultExceptionMappers: false
applicationConnectors:
- type: http
port: 8080

Related

Spring Boot app in Docker receives: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

I have a Spring Boot app in Docker that runs on Heroku.
Recently, after updating Tomcat to 10.1.0-M10, I started getting this error:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within
60 seconds of launch
The immediate thought of downgrading to lower versions doesn't work due to vulnerabilities in the earlier versions. I have checked possible causes and found Tomcat binding port issue.
I cannot set up fixed config for different ports as I am deploying to Heroku and dependent on their random ports.
My Dockerfile:
FROM azul/zulu-openjdk-alpine:11
ENV PORT=$PORT
COPY /target/app.jar /app.jar
CMD java -Xms256m -Xmx512m \
-Dlog4j2.formatMsgNoLookups=true \
-Djava.security.egd=file:/dev/./urandom \
-Dserver.port=$PORT \
-jar /app.jar
What is the way to solve it? Is there anything I am missing?
UPDATE:
There are more logs from Heroku:
Feb 22 12:50:16 integration-test app/web.1 2022-02-22 20:50:16.057 [main] INFO c.g.s.z.ApplicationKt - Started ApplicationKt in 8.09 seconds (JVM running for 9.062)
Feb 22 12:50:16 integration-test app/web.1 2022-02-22 20:50:16.060 [main] DEBUG o.s.b.a.ApplicationAvailabilityBean - Application availability state LivenessState changed to CORRECT
Feb 22 12:50:16 integration-test app/web.1 2022-02-22 20:50:16.063 [main] DEBUG o.s.b.a.ApplicationAvailabilityBean - Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
Feb 22 12:51:06 integration-test heroku/web.1 Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
I found a solution that wasn't perfect but seemed to work for me.
Downgraded Spring Boot from 2.6.3 to 2.6.1
Downgraded Tomcat from 10.X.X to 9.X.X
Removed dev tools dependencies
I think the two latest did the magic. Dev tools stopped asking for an extra port in the test/prod environment. Tomcat bound the port in the version 9.X.X but not in 10.X.X.
Even though I found the solution, I don't know why it behaved like this, and it isn't perfect security-wise.
from the error message it seems that $PORT is not resolved to any environment variable.
deploying to heroku you must use .env file to define env vars (you can't use docker run -e PORT=1234) see documentation
When you use heroku locally, you can set config vars in a .env file. When heroku local is run .env is read and each name/value pair is set in the environment. You can use this same .env file when using Docker: docker run -p 5000:5000 --env-file .env <image-name>

Launching spring boot application gives error : org.springframework.boot.web.server.PortInUseException: Port 8080 is already in use

While launching spring-boot application, I am always getting the below error.
I tried changing the ports to 8181, 8585, 9191, etc but still the same error.
I tried everything mentioned in Launching Spring application Address already in use but nothing worked for me.
Also, this was working fine until yesterday and stopped working when I added spring-actuator related maven dependency and properties (this is my observation not sure even if it is related).
Error :
2021-05-20 18:15:21.283 DEBUG 10256 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
Application failed to start due to an exception
org.springframework.boot.web.server.PortInUseException: Port 8080 is already in use
at org.springframework.boot.web.server.PortInUseException.lambda$throwIfPortBindingException$0(PortInUseException.java:70) ~[spring-boot-2.4.5.jar:2.4.5]
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8080 was already in use.
Action:
Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
My application.properties:
logging.level.org.springframework = debug
server.port=8080
management.endpoints.web.exposure.include=*
Any suggestion, please ?
Thanks for your help in advance.
There must be some application running or already using port 8080 in your system.
Here are few suggestions that might help.
open command prompt and try :
> netstat -aon | find /i "8080"
output>
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 13568
TCP [::]:8080 [::]:0 LISTENING 13568
The last number shown in the above output is PID for running port 8080, try to kill that process.
Note: PID might differ in your system
>taskkill /F /PID 13568
If this doesn't work, then try restating your IDE and change the port.
Also, you mentioned that problem started when you added actuator dependencies. Please check once by removing those dependencies and properties, not sure if hal-explorer is creating the problem.
Problem is solved Thanks :))))

Heroku Java application timing out after 90 seconds

I have been trying to host a discord bot on heroku for some time now. I Have everything set up now but the connection keeps timing out after 90 seconds because it cannot sustain a connection and I am not sure what is wrong.
Procfile: web: java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes:target/dependency/* com.marcuzzo.JDABot.Bot
Error log:
2020-07-17T17:54:47.513540+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dserver.port=7699 -cp target/classes:target/dependency/* com.marcuzzo.JDABot.Bot`
2020-07-17T17:54:49.238091+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-07-17T17:54:49.241547+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-07-17T17:54:50.386750+00:00 app[web.1]: 938 [main] INFO net.dv8tion.jda.api.JDA - Login Successful!
2020-07-17T17:54:50.526175+00:00 app[web.1]: 1078 [JDA MainWS-WriteThread] INFO net.dv8tion.jda.internal.requests.WebSocketClient - Connected to WebSocket
2020-07-17T17:54:50.862291+00:00 app[web.1]: 1414 [JDA MainWS-ReadThread] INFO net.dv8tion.jda.api.JDA - Finished Loading!
2020-07-17T17:56:18.105532+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2020-07-17T17:56:18.120426+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-07-17T17:56:18.198101+00:00 heroku[web.1]: Process exited with status 137
2020-07-17T17:56:18.243205+00:00 heroku[web.1]: State changed from starting to crashed
I have been told to change the dyno in my procfile to anything OTHER then web but while the build succeeds, the bot never goes online if I were to use something like bot.
This post tells me to call a listen() method but I think this was either written for python or it is part of a library I do not know about.
My application is pretty short considering I am just focused on getting it hosted:
package com.marcuzzo.JDABot;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
public class Bot {
public static void main (String[] args) {
int port = Integer.parseInt(System.getenv("PORT"));
// String host = "0.0.0.0";
String token = "insert token here";
try {
JDA jda = JDABuilder.createDefault(token).build();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I am not sure if there is a certain method in the JDA library I am using that would solve this problem but I have not found any so far.
Looks like your bot is not web app. You should use worker heroku configuration. Please check https://devcenter.heroku.com/articles/run-non-web-java-processes-on-heroku

Deploying to Heroku crash: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch

I get this error after deploying my springboot application in Heroku:
2019-12-12T19:09:35.340701+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-12T19:09:35.088497+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2019-12-12T19:09:35.088497+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-12-12T19:09:35.319755+00:00 heroku[web.1]: Process exited with status 137
2019-12-12T19:16:46.351647+00:00 heroku[web.1]: State changed from crashed to starting
2019-12-12T19:16:50.604492+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=35960 $JAVA_OPTS -jar build/libs/*.jar`
So I tried to make a Procfile on the root folder of my project and this is the content:
Procfile:
web: java -Dserver.port=$PORT -jar build/libs/*.jar
I also added this line to my application.properties file.
application.properties:
server.port=${PORT:5000}
However, it's still not working.
The error above is still happening. How do I fix this? What else am I missing?
I'm using gradle, java11 and spring boot.

cannot start tomcat6 in linux environment

i just installed tomcat6 via yum
where i input a command: service tomcat6 start
Starting tomcat6: [ OK ]
but i use the command service tomcat6 status, it shows failed
PID file exists, but process is not running [FAILED]
i had tried the solution inside this thread
I don't understand the results from #service tomcat6 status
but not still get it work, could anyone help?
Please do force my question as duplicated, i had already tried
PID file exists, but process is not running
, it not work for my case, see my comment
- service tomcat6 start
Starting tomcat6: [FAILED]
- service tomcat6 stop
Stopping tomcat6: [ OK ]
- service tomcat6 status
tomcat6 (pid ) is running...

Categories

Resources