0

I am trying to run my golang web app on heroku. It will upload successfully but then it will crash with a code of "H10". However, it also gives me error R10 and states: " Web process failed to bind to $PORT within 60 seconds of launch".

Is there an issue with it trying to find the port which is clearly set in the file (and works on my computer) or is there some other issue. There is currently no database linked to the app (which according to heroku is a common cause for this crash) but it is using gorilla/mux as a dependency that is vendored so that could be the issue.

1 Answers1

3

See this

It appears you cannot specify an arbitrary port but must check the environment for the PORT assigned by heroku for your deployment.

You may do this with e.g.

port:=os.Getenv("PORT")

Then use port with your server.

Please include code (even a repro) with questions to make it easier for us to understand the problem.

halfer
  • 19,824
  • 17
  • 99
  • 186
DazWilkin
  • 32,823
  • 5
  • 47
  • 88
  • I have tried setting a PORT environment variable in Heroku both through their website and in the program itself. It once again works fine on my machine but provides the same error in Heroku. – Henry Wojnicki Feb 18 '20 at 23:43
  • To reiterate, you can't set the port, you just use the value assigned by the platform. Please paste your code in your question. – DazWilkin Feb 19 '20 at 00:03
  • the line for the port is as follows `log.Fatal(http.ListenAndServe(os.Getenv("PORT"), router))` This should work regardless of whether I am allowed to set the port or not right? – Henry Wojnicki Feb 19 '20 at 00:42
  • Actually you need to prefix it with at least a colon as it represents the host:path – DazWilkin Feb 19 '20 at 00:58
  • 1
    So `...fmt.Sprintf(":%s", os.Getenv("PORT"))...` – DazWilkin Feb 19 '20 at 00:59
  • it is finally working. Thank you so much for your help and patience! – Henry Wojnicki Feb 19 '20 at 02:56