Home >Backend Development >Golang >Why Does My Golang App on Heroku Show an 'Application Error' After a Successful Build?
Deploying a Golang App on Heroku: Build Success, But Application Error
When deploying a Golang application on Heroku with Go dependency support, you may encounter an "Application Error" when attempting to access endpoints. This issue arises when the web server is not properly bound to the appropriate port on Heroku.
Your application log messages indicate the following error:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Cause:
The issue is caused by attempting to start the server on a hardcoded port (9000) instead of binding it to the port specified by Heroku's $PORT environment variable.
Solution:
To resolve this issue, start the server on the correct port by using the $PORT environment variable. Replace your existing code:
err := grace.Serve(":9000", context.ClearHandler(http.DefaultServeMux))
With the following:
port := os.Getenv("PORT") if port == "" { port = "9000" // Default port if not specified } err := grace.Serve(":" + port, context.ClearHandler(http.DefaultServeMux))
This change ensures that the server properly binds to the port specified by Heroku, resolving the "Application Error" issue.
The above is the detailed content of Why Does My Golang App on Heroku Show an 'Application Error' After a Successful Build?. For more information, please follow other related articles on the PHP Chinese website!