Heroku "Connection closed without response" H13 with golang after http 503

476 Views Asked by At

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

0

There are 0 best solutions below