Question:
Deploying a GoLang app on Heroku using GoDep support, the build succeeds but accessing the endpoint returns an "Application Error." The app runs on port 9000 on localhost, but grace.Serve seems to be listening on a different port.
Heroku Log Output:
2019-07-08T05:03:48.131507+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Application Code:
err := grace.Serve(":9000", context.ClearHandler(http.DefaultServeMux))
Answer:
The issue is that the application is explicitly binding its webserver to port 9000, which conflicts with Heroku's assigned port. Heroku assigns a dynamic port through the environment variable PORT.
To resolve this, the application should dynamically assign the port based on the PORT environment variable instead of hardcoding port 9000.
Revised Application Code:
port := os.Getenv("PORT") if port == "" { port = "9000" // Default port if not specified } err := grace.Serve(":" + port, context.ClearHandler(http.DefaultServeMux))
The above is the detailed content of Why Does My GoLang Heroku App Return an 'Application Error' Despite a Successful Build?. For more information, please follow other related articles on the PHP Chinese website!