1

I am really hitting something I don't understand here and would really love some help! Appreciated.

Basically, I have a Heroku app running a basic go server

    s := &http.Server{
        Addr: ":" + Port,
        Handler: handler
    }
    err := s.ListenAndServe()

The goal of my app is to perform authenticated requests to the spotify API. For this I have to login, s I use the great go client (https://github.com/zmb3/spotify).

When I create my user, it seems because spotify API is a bit unstable that it sends me a 503. Looking at the logs, I get

2021/03/09 22:51:47 couldn't create token: oauth2: cannot fetch token: 503 Service Unavailable

This is where it gets tricky, from there all starts to crash and burn. I then get a

Response: upstream connect error or disconnect/reset before headers. reset reason: connection termination

at=error code=H13 desc="Connection closed without response" method=GET path="/rooms/V59TPC" host=api.sharedspotify.com request_id=8fee4d42-b7ad-4f31-a601-d3771e029362 fwd="92.184.105.234" dyno=web.1 connect=0ms service=151ms status=503 bytes=0 protocol=https

Process exited with status 1

Looking at what everything says on the subject, I am trying to get the solution right and this is where I need a bit of help.

After reading Heroku documentation, I saw that H13 is caused by


H13 - Connection closed without response

This error is thrown when a process in your web dyno accepts a connection, but then closes the socket without writing anything to it.

One example where this might happen is when a Unicorn web server is configured with a timeout shorter than 30s and a request has not been processed by a worker before the timeout happens. In this case, Unicorn closes the connection before any data is written, resulting in an H13.


So what I thought doing is change the server timeouts to be more than 30s, what do you think? is this the right solution ?

    s := &http.Server{
        Addr: ":" + Port,
        Handler: handler,
        ReadTimeout:  60 * time.Second,
        WriteTimeout: 100 * time.Second,
        IdleTimeout:  1200 * time.Second,
    }
    err := s.ListenAndServe()

Many thanks

Paul Vidal
  • 11
  • 1
  • sometime its simpler to manually make the REST calls directly on the command line using curl to call the underlying REST api and get that working especially to troubleshoot initial setup challenges like getting it to do the simplest auth connection ... then once that is working graduate up to leveraging a wrapper around REST to make that same call ... trying to battle the wrapper plus the auth muddies the waters ... also do the curl calls from a terminal on your laptop first before pushing working code up to the cloud heroku – Scott Stensland Mar 12 '21 at 15:31
  • Thanks for the response Scott :) I already did all that and everything is working fine, what I need is a production app running on Heroku so I need to get this problem sorted, but maybe I should drop the wrapper. I'd prefer find another way though – Paul Vidal Mar 12 '21 at 16:13
  • I'd try on Heroku without the wrapper to see if issue is Heroku related or not ... personally I like to execute dev code on a rented VPS ubuntu box or whatever OS matches your production box which is exactly why I also run ubuntu on my laptop YMMV – Scott Stensland Mar 12 '21 at 16:23

0 Answers0