Heroku application error when deploy go fiber app - go

When I deploy my go fiber app to heroku, I got the following error
2022-08-23T15:33:03.334087+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/swagger/index.html" host=vast-ocean-37337.herokuapp.com request_id=9161bdfc-ff62-4b5e-bd99-1649f7f5e569 fwd="173.32.236.24" dyno= connect= service= status=503 bytes= protocol=https
and this is my main.go file
package main
import (
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/recover"
"rocketstothemoon.com/configs"
"rocketstothemoon.com/routes"
fiber_swagger "github.com/swaggo/fiber-swagger"
_ "rocketstothemoon.com/docs"
)
func main() {
app := fiber.New()
app.Use(recover.New())
app.Use(cors.New())
configs.ConnectDB()
routes.UserRoute(app)
app.Get("/swagger/*", fiber_swagger.WrapHandler)
serveStatic(app)
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
app.Listen(":" + port)
}
func serveStatic(app *fiber.App) {
app.Static("/", "./build")
}
It works perfectly fine in my local, but keep throwing this error in heroku.
I have changed my port to os.Getenv("PORT") but it doesn't help, any help?

Related

Received "cannot execute binary file: Exec format error" while pushing golang project to heroku. Why is this happening?

I have been recently attempting to deploy a simple golang app to heroku using the same method I used to deploy previous ones, and I'm running into error with my procfile execution.
2021-07-06T23:30:28.000000+00:00 app[api]: Build started by user user#yahoo.com
2021-07-06T23:30:40.271575+00:00 app[api]: Release v7 created by user user#yahoo.com
2021-07-06T23:30:40.271575+00:00 app[api]: Deploy 0d19e552 by user user#yahoo.com
2021-07-06T23:30:40.909377+00:00 heroku[web.1]: State changed from crashed to starting
2021-07-06T23:30:42.049118+00:00 heroku[web.1]: Starting process with command `bin/main`
2021-07-06T23:30:45.582197+00:00 app[web.1]: bash: bin/main: cannot execute binary file: Exec format error
2021-07-06T23:30:45.646220+00:00 heroku[web.1]: Process exited with status 126
2021-07-06T23:30:45.722720+00:00 heroku[web.1]: State changed from starting to crashed
2021-07-06T23:30:57.000000+00:00 app[api]: Build succeeded
2021-07-06T23:45:41.986316+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=testing-my-message-app.herokuapp.com request_id=fd3a8259-82dc-489f-b206-060ec0d8f8f6 fwd="67.81.209.179" dyno= connect= service= status=503 bytes= protocol=https
2021-07-06T23:45:42.522223+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=testing-my-message-app.herokuapp.com request_id=f3268609-cdcc-4c16-af24-f7dfa5568030 fwd="67.81.209.179" dyno= connect= service= status=503 bytes= protocol=https
I tried running both go build -o bin/main and go build -o bin/main -v .to build the binary file, but heroku is unable to build it for due to format error. How can I fix this? I'm running on a 64 bit window platform for reference.
Also, just in case, here is the code I am trying to deploy.
package main
import (
"fmt"
"log"
"net/http"
"os"
"strconv"
"github.com/go-chi/chi"
"github.com/go-chi/render"
"github.com/joho/godotenv"
)
type m map[string]interface{}
func main(){
godotenv.Load()
router := chi.NewRouter()
words := m{
"black": 10,
"red": 7,
"pink": 0,
"yellow": 5,
"blue": 9,
}
router.Get("/all", func(res http.ResponseWriter, req *http.Request) {
render.JSON(res, req, words)
})
router.Get("/add-color-rating/{color}/{rating}", func(res http.ResponseWriter, req *http.Request) {
color := chi.URLParam(req, "color")
rating, _ := strconv.Atoi(chi.URLParam(req, "rating"))
words[color] = rating
render.JSON(res, req, m{"added-rating": m{color: rating}})
})
fs := http.FileServer(http.Dir("./static"))
router.Handle("/static/*", http.StripPrefix("/static", fs))
fmt.Println("running on port:", os.Getenv("PORT"))
log.Fatal(http.ListenAndServe(os.Getenv("PORT"), router))
}
It could also be that you are trying to run an executable compiled for a specific architecture on a platform with a different architecture. Try specifying the the target os and architecture in which you expect to run the build as follows.
env GOOS=linux GOARCH=arm64 go build -o bin/main
If you're trying to build files in the bin/main folder, you need to do this:
go build bin/main
If you are trying to build in the current folder, you need to do this:
go build -o bin/main.exe
https://golang.org/cmd/go#hdr-Compile_packages_and_dependencies

Deploying application to heroku porting issue [duplicate]

My golang app runs on port 9000 at my localhost. After deploying it at heroku using godep support, i was able to push and deploy at heroku. However when i try to access the endpoint e.g '/', it shows Application Error. You can see below my code and log while deploying at heroku
package main
import (
"log"
"fmt"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/gorilla/context"
"gopkg.in/paytm/grace.v1"
// utilhttp "bitbucket.org/michaelchandrag/chit/pkg/util/http"
// util "bitbucket.org/michalechandrag/chit/pkg/util"
)
func main() {
log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ CHIT STARTED $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
muxRouter := mux.NewRouter()
muxRouter.HandleFunc("/", Articles)
http.Handle("/", muxRouter)
// err = grace.Serve(":"+cfg.Server.Port, context.ClearHandler(http.DefaultServeMux))
err := grace.Serve(":9000", 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
}*/
}
heroku logs while deploying
-----> 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
app logs before and after access endpoint
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
2019-07-08T13:33:25.021835+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=michaelchandrag-project.herokuapp.com request_id=e6b5c93a-7177-4080-9858-ed925a20c513 fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T13:33:25.566036+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=michaelchandrag-project.herokuapp.com request_id=35c741a9-be4d-48f6-ba99-ba24ddc58b9b fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T13:48:38.294082+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=michaelchandrag-project.herokuapp.com request_id=57a3a243-58f4-4efe-b478-eb660d84fe1f fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T13:48:38.616077+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=michaelchandrag-project.herokuapp.com request_id=0687b8a8-86ae-4c49-a37f-9cbf9e0f75de fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
Your app starts but is getting killed because you don't bind your webserver to the specified port. This is clear from the 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
On Heroku you have to bind your HTTP server to the port specified by the PORT environment variable. Your app will be publicly available on default HTTP and HTTPS ports with the help of Heroku gateways.
So start your server on the expected port. Instead of this:
err := grace.Serve(":9000", context.ClearHandler(http.DefaultServeMux))
Do this:
port := os.Getenv("PORT")
if port == "" {
port = "9000" // Default port if not specified
}
err := grace.Serve(":" + port, context.ClearHandler(http.DefaultServeMux))

go heroku web process failed to bind to $PORT within 60 seconds of launch [duplicate]

My golang app runs on port 9000 at my localhost. After deploying it at heroku using godep support, i was able to push and deploy at heroku. However when i try to access the endpoint e.g '/', it shows Application Error. You can see below my code and log while deploying at heroku
package main
import (
"log"
"fmt"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/gorilla/context"
"gopkg.in/paytm/grace.v1"
// utilhttp "bitbucket.org/michaelchandrag/chit/pkg/util/http"
// util "bitbucket.org/michalechandrag/chit/pkg/util"
)
func main() {
log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ CHIT STARTED $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
muxRouter := mux.NewRouter()
muxRouter.HandleFunc("/", Articles)
http.Handle("/", muxRouter)
// err = grace.Serve(":"+cfg.Server.Port, context.ClearHandler(http.DefaultServeMux))
err := grace.Serve(":9000", 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
}*/
}
heroku logs while deploying
-----> 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
app logs before and after access endpoint
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
2019-07-08T13:33:25.021835+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=michaelchandrag-project.herokuapp.com request_id=e6b5c93a-7177-4080-9858-ed925a20c513 fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T13:33:25.566036+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=michaelchandrag-project.herokuapp.com request_id=35c741a9-be4d-48f6-ba99-ba24ddc58b9b fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T13:48:38.294082+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=michaelchandrag-project.herokuapp.com request_id=57a3a243-58f4-4efe-b478-eb660d84fe1f fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T13:48:38.616077+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=michaelchandrag-project.herokuapp.com request_id=0687b8a8-86ae-4c49-a37f-9cbf9e0f75de fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
Your app starts but is getting killed because you don't bind your webserver to the specified port. This is clear from the 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
On Heroku you have to bind your HTTP server to the port specified by the PORT environment variable. Your app will be publicly available on default HTTP and HTTPS ports with the help of Heroku gateways.
So start your server on the expected port. Instead of this:
err := grace.Serve(":9000", context.ClearHandler(http.DefaultServeMux))
Do this:
port := os.Getenv("PORT")
if port == "" {
port = "9000" // Default port if not specified
}
err := grace.Serve(":" + port, context.ClearHandler(http.DefaultServeMux))

Heroku Application Error - code=H10 desc="App crashed"

I am trying to deploy a dash app on heroku.
Everything works fine (also locally) except from when I run heroku open I get this Application Error:
heroku logs --tail then gives:
2019-11-22T22:55:41.598239+00:00 heroku[web.1]: State changed from up to crashed
2019-11-22T22:55:41.587218+00:00 heroku[web.1]: Process exited with status 3
2019-11-22T22:55:42.000000+00:00 app[api]: Build succeeded
2019-11-22T22:55:59.485489+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=romania2019.herokuapp.com request_id=d48fde4a-bd7e-47e2-9a21-bdf589ef281a fwd="152.115.83.242" dyno= connect= service= status=503 bytes= protocol=https
2019-11-22T22:55:59.851491+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=romania2019.herokuapp.com request_id=b6bbb5e8-8667-42f2-b083-b7bf26b5ae14 fwd="152.115.83.242" dyno= connect= service= status=503 bytes= protocol=https
Any suggestions where I should look next?
Here is my app.py I am trying to deploy:
import datetime
import time
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly
from dash.dependencies import Input, Output
import numpy as np
from selenium import webdriver
url = 'https://prezenta.bec.ro/prezidentiale24112019/abroad-precincts'
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.preferences.instantApply",True)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
"text/plain, application/octet-stream, application/binary, text/csv, application/csv, application/excel, text/comma-separated-values, text/xml, application/xml")
profile.set_preference("browser.helperApps.alwaysAsk.force",False)
profile.set_preference("browser.download.manager.showWhenStarting",False)
profile.set_preference("browser.download.folderList",1)
options = webdriver.FirefoxOptions()
options.headless = True
# create a new Firefox session
driver = webdriver.Firefox(firefox_profile=profile, options=options)
driver.implicitly_wait(30)
driver.get(url)
# Find button and click on it
ELEMENT = driver.find_element_by_xpath('//*[#id="root"]/main/section/div[1]/div[1]/div[5]/div/div[2]/div/h2')
def update(ELEMENT):
# time.sleep(2.9)
return int(ELEMENT.text.replace('.', ''))
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
app.layout = html.Div(
html.Div([
html.H4('ROMANIA - Presidential Elections Live Feed'),
html.Div(id='live-update-text'),
dcc.Graph(id='live-update-graph'),
dcc.Interval(
id='interval-component',
interval=60*1000, # in milliseconds
n_intervals=0
)
])
)
time.sleep(5)
#app.callback(Output('live-update-text', 'children'),
[Input('interval-component', 'n_intervals')])
def update_metrics(n):
no = update(ELEMENT)
style = {'padding': '5px', 'fontSize': '16px'}
return [
html.Span('Voters: {}'.format(no), style=style),
html.Span('Voters/Min: {}'.format(np.diff(data['number'])[-5:].mean()), style=style)
]
data = {'time': [], 'number': []}
# Multiple components can update everytime interval gets fired.
#app.callback(Output('live-update-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def update_graph_live(n):
# Collect some data
data['time'].append(datetime.datetime.now()) # + datetime.timedelta(seconds=3))
try:
no = update(ELEMENT)
data['number'].append(no)
except:
data['number'].append(no)
# Create the graph with subplots
fig = plotly.subplots.make_subplots(rows=2, cols=1, vertical_spacing=0.1)
fig['layout']['margin'] = {
'l': 30, 'r': 10, 'b': 30, 't': 10
}
fig['layout']['legend'] = {'x': 0, 'y': 1, 'xanchor': 'left'}
fig.append_trace({
'x': data['time'],
'y': data['number'],
'name': 'Voters',
'type': 'scatter'
}, 1, 1)
fig.append_trace({
'x': data['time'],
'y': np.diff(data['number']),
'text': data['time'],
'name': 'Voters / Min',
'type': 'scatter'
}, 2, 1)
fig.layout.update(height=800, )
return fig
if __name__ == '__main__':
app.run_server(debug=True)
It basically reads the number of voters and displays the number of votes per minute.
And the deployment instructions I've been following are given here: https://dash.plot.ly/deployment.
open your git bash and post
log --tails it will show your the error type H10 is app crasing due to some error missing dependencies or your procfiles is not well set so try reading the error types and look in your code. if your app is working fine in your local host try
web: gunicorn index:server --preload --timeout60.

Deploying a golang app on heroku, build succeed but application error

My golang app runs on port 9000 at my localhost. After deploying it at heroku using godep support, i was able to push and deploy at heroku. However when i try to access the endpoint e.g '/', it shows Application Error. You can see below my code and log while deploying at heroku
package main
import (
"log"
"fmt"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/gorilla/context"
"gopkg.in/paytm/grace.v1"
// utilhttp "bitbucket.org/michaelchandrag/chit/pkg/util/http"
// util "bitbucket.org/michalechandrag/chit/pkg/util"
)
func main() {
log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ CHIT STARTED $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
muxRouter := mux.NewRouter()
muxRouter.HandleFunc("/", Articles)
http.Handle("/", muxRouter)
// err = grace.Serve(":"+cfg.Server.Port, context.ClearHandler(http.DefaultServeMux))
err := grace.Serve(":9000", 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
}*/
}
heroku logs while deploying
-----> 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
app logs before and after access endpoint
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
2019-07-08T13:33:25.021835+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=michaelchandrag-project.herokuapp.com request_id=e6b5c93a-7177-4080-9858-ed925a20c513 fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T13:33:25.566036+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=michaelchandrag-project.herokuapp.com request_id=35c741a9-be4d-48f6-ba99-ba24ddc58b9b fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T13:48:38.294082+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=michaelchandrag-project.herokuapp.com request_id=57a3a243-58f4-4efe-b478-eb660d84fe1f fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
2019-07-08T13:48:38.616077+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=michaelchandrag-project.herokuapp.com request_id=0687b8a8-86ae-4c49-a37f-9cbf9e0f75de fwd="36.74.35.162" dyno= connect= service= status=503 bytes= protocol=https
Your app starts but is getting killed because you don't bind your webserver to the specified port. This is clear from the 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
On Heroku you have to bind your HTTP server to the port specified by the PORT environment variable. Your app will be publicly available on default HTTP and HTTPS ports with the help of Heroku gateways.
So start your server on the expected port. Instead of this:
err := grace.Serve(":9000", context.ClearHandler(http.DefaultServeMux))
Do this:
port := os.Getenv("PORT")
if port == "" {
port = "9000" // Default port if not specified
}
err := grace.Serve(":" + port, context.ClearHandler(http.DefaultServeMux))

Resources