


Why does my Go app deployment on Heroku succeed, yet the application displays an 'Application Error,' despite the build succeeding?
Deploying a golang app on Heroku: Build succeeds but application shows error
Problem
When deploying a Go application on Heroku using godep support, the build succeeds, but accessing the endpoint results in an "Application Error."
Code and Logs
The following code is used in the application:
import ( "log" "fmt" "net/http" "os" "github.com/gorilla/mux" "github.com/gorilla/context" "gopkg.in/paytm/grace.v1" ) func main() { log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ CHIT STARTED $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$") muxRouter := mux.NewRouter() muxRouter.HandleFunc("/", Articles) http.Handle("/", muxRouter) port := os.Getenv("PORT") if port == "" { port = "9000" // Default port if not specified } err := grace.Serve(":" + port, context.ClearHandler(http.DefaultServeMux)) if err != nil { log.Println("[ERROR GRACEFUL]", err) os.Exit(1) } os.Exit(0) } func Articles(w http.ResponseWriter, r *http.Request) { // vars := mux.Vars(r) w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Hello") // r.Close = true // w.Header().Set("Content-Type", "application/json") // w.Header().Set("Access-Control-Allow-Origin", "*") /*if r.Method == "OPTIONS" { w.WriteHeader(http.StatusOK) return } if err := fn(w, r); err != nil { log.Println(err) apiObject := ConstructAPIError(http.StatusInternalServerError, ErrGeneral, SysMsgErrGeneral, MsgErrGeneral) SendAPIObject(w, apiObject) return }*/ }
The Heroku logs during deployment are as follows:
-----> Go app detected -----> Fetching jq... done -----> Fetching stdlib.sh.v8... done -----> Checking Godeps/Godeps.json file. -----> New Go Version, clearing old cache -----> Installing go1.12.6 -----> Fetching go1.12.6.linux-amd64.tar.gz... done -----> Running: go install -v -tags heroku ./... bitbucket.org/michaelchandrag/chit/pkg bitbucket.org/michaelchandrag/chit/vendor/github.com/gorilla/context bitbucket.org/michaelchandrag/chit/vendor/github.com/gorilla/mux bitbucket.org/michaelchandrag/chit/vendor/gopkg.in/tylerb/graceful.v1 bitbucket.org/michaelchandrag/chit/vendor/gopkg.in/paytm/grace.v1 bitbucket.org/michaelchandrag/chit/pkg/util bitbucket.org/michaelchandrag/chit Installed the following binaries: ./bin/chit -----> Discovering process types Procfile declares types -> web -----> Compressing... Done: 7.5M -----> Launching... Released v3 https://michaelchandrag-project.herokuapp.com/ deployed to Heroku
The application logs before and after accessing the endpoint are:
2:47.954106+00:00 heroku[web.1]: Starting process with command `chit` 2019-07-08T05:02:49.413453+00:00 app[web.1]: 2019/07/08 05:02:49 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ CHIT STARTED $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 2019-07-08T05:02:49.413476+00:00 app[web.1]: 2019/07/08 05:02:49 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 2019-07-08T05:02:49.413647+00:00 app[web.1]: 2019/07/08 05:02:49 starting serve on :9000 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 2019-07-08T05:03:48.131595+00:00 heroku[web.1]: Stopping process with SIGKILL 2019-07-08T05:03:48.214979+00:00 heroku[web.1]: State changed from starting to crashed 2019-07-08T05:03:48.193205+00:00 heroku[web.1]: Process exited with status 137 2019-07-08T10:38:59.721224+00:00 heroku[web.1]: State changed from crashed to starting 2019-07-08T10:39:00.359017+00:00 heroku[web.1]: Starting process with command `chit` 2019-07-08T10:39:02.232435+00:00 app[web.1]: 2019/07/08 10:39:02 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ CHIT STARTED $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 2019-07-08T10:39:02.232458+00:00 app[web.1]: 2019/07/08 10:39:02 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 2019-07-08T10:39:02.232583+00:00 app[web.1]: 2019/07/08 10:39:02 starting serve on :9000 2019-07-08T10:40:00.462841+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 2019-07-08T10:40:00.462974+00:00 heroku[web.1]: Stopping process with SIGKILL 2019-07-08T10:40:00.555959+00:00 heroku[web.1]: Process exited with status 137 2019-07-08T10:40:00.573427+00:00 heroku[web.1]: State changed from starting to crashed
Solution
The application starts but is getting killed because it does not bind to the specified port. This is evident from the Heroku log message:
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
To resolve this issue, the webserver must be bound to the port specified by the PORT environment variable. On Heroku, the HTTP server is publicly available on default HTTP and HTTPS ports through Heroku gateways.
Therefore, the application should bind to the specified port instead of :9000.
The above is the detailed content of Why does my Go app deployment on Heroku succeed, yet the application displays an 'Application Error,' despite the build succeeding?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

OpenSSL, as an open source library widely used in secure communications, provides encryption algorithms, keys and certificate management functions. However, there are some known security vulnerabilities in its historical version, some of which are extremely harmful. This article will focus on common vulnerabilities and response measures for OpenSSL in Debian systems. DebianOpenSSL known vulnerabilities: OpenSSL has experienced several serious vulnerabilities, such as: Heart Bleeding Vulnerability (CVE-2014-0160): This vulnerability affects OpenSSL 1.0.1 to 1.0.1f and 1.0.2 to 1.0.2 beta versions. An attacker can use this vulnerability to unauthorized read sensitive information on the server, including encryption keys, etc.

Under the BeegoORM framework, how to specify the database associated with the model? Many Beego projects require multiple databases to be operated simultaneously. When using Beego...

Backend learning path: The exploration journey from front-end to back-end As a back-end beginner who transforms from front-end development, you already have the foundation of nodejs,...

What should I do if the custom structure labels in GoLand are not displayed? When using GoLand for Go language development, many developers will encounter custom structure tags...

The problem of using RedisStream to implement message queues in Go language is using Go language and Redis...

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys
