dial tcp i/o timeout with HTTP GET request
Asked Answered
O

2

10

Running into some error, I must be overlooking something. How can I debug this? Dropping connections?

I read the following:
golang - Why net.DialTimeout get timeout half of the time?
Go. Get error i/o timeout in server program
golang get massive read tcp ip:port i/o timeout in ubuntu 14.04 LTS
Locating the "read tcp" error in the Go source code
Getting sporadic "http: proxy error: read tcp: i/o timeout" on Heroku

Error created here: https://github.com/golang/go/blob/b115207baf6c2decc3820ada4574ef4e5ad940ec/src/net/net.go#L179

Goal: Send a Get request to a url.
Expected result: return body in JSON.
Encountered problem: I/O timeout

It works in Postman
Edit: I added a modified timeout...

Edit2: traced error

Postman request:

GET /v2/XRP-EUR/candles?interval=1h HTTP/1.1
Host: api.bitvavo.com

Postman Result (1440 rows):

[
    [
        1609632000000,
        "0.17795",
        "0.17795",
        "0.17541",
        "0.17592",
        "199399.874013"
    ],
    [
        1609628400000,
        "0.17937",
        "0.18006",
        "0.17622",
        "0.17852",
        "599402.631894"
    ],
    [
        1609624800000,
        "0.18167",
        "0.18167",
        "0.17724",
        "0.17984",
        "579217.962574"
    ],.....

Code:

package main

import (
    "fmt"
    "net/http"
    "io/ioutil"
    "time"
)

func main() {
    url := "https://api.bitvavo.com/v2/XRP-EUR/candles?interval=1h"
    method := "GET"

    client := &http.Client {
    }
    client.Timeout = time.Second * 60
    req, err := http.NewRequest(method, url, nil)

    if err != nil {
        fmt.Println(err)
        return
    }
    res, err := client.Do(req)
    if err != nil {
        fmt.Println(err)
        return
    }
    defer res.Body.Close()

    body, err := ioutil.ReadAll(res.Body)
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println(string(body))
}

result:

Get "https://api.bitvavo.com/v2/XRP-EUR/candles?interval=1h": dial tcp 65.9.73.10:443: i/o timeout
Oleviaolfaction answered 3/1, 2021 at 0:39 Comment(1)
The application works for me. There's a problem with your local environment or the server is refusing connections from your IP address.Variscite
O
2

Local environment, firewall not allowing golang to dial tcp..
It still allowed the url to be resolved to an ip though (DNS)

Solution: Change firewall settings on the host to allow the application to connect or temporarily switch off the firewall to test, Check Docker/kubernetes/reverse proxy settings

Oleviaolfaction answered 3/1, 2021 at 12:17 Comment(2)
So? What is the proposed solution, change firewall setting locally?Verbalism
Open up the firewall to prevent it from blocking this requestKriskrischer
T
6

I was with this issue when building inside docker containers.

Not sure why, but after a docker swarm leave --force and a systemctl restart docker the build worked.

Trott answered 31/3, 2021 at 22:22 Comment(1)
For me, systemctl restart docker was enough to fix the problem.Nape
O
2

Local environment, firewall not allowing golang to dial tcp..
It still allowed the url to be resolved to an ip though (DNS)

Solution: Change firewall settings on the host to allow the application to connect or temporarily switch off the firewall to test, Check Docker/kubernetes/reverse proxy settings

Oleviaolfaction answered 3/1, 2021 at 12:17 Comment(2)
So? What is the proposed solution, change firewall setting locally?Verbalism
Open up the firewall to prevent it from blocking this requestKriskrischer

© 2022 - 2025 — McMap. All rights reserved.