skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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>

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search