NewRequest returning "443 connect: bad file descriptor"

Hi, I have a method that wraps http.NewRequest:

func Request(url string, token string, params map[string]string) (*http.Response, error) {
	client := &http.Client{
		Timeout: time.Second * 15,
	req, err := http.NewRequest(http.MethodGet, url, nil)
	q := req.URL.Query()
	for i, v := range params {
		q.Add(i, v)
	req.URL.RawQuery = q.Encode()

	req.Header.Set("PRIVATE-TOKEN", token)
	req.Header.Set("Content-Type", "application/json")
	if err != nil {
		return nil, err
	return client.Do(req)
params := map[string]string{
    "membership": "true",
    "statistics": "true",

resp, err := gitlabutils.Request("", token, params)

Is there any reason why err is:

error="Get \"\": dial tcp [2606:4700:90:0:f22e:fbec:5bed:a9b9]:443: connect: bad file descriptor" 

What would cause a connect: bad file descriptor ? Any ideas?


Your code is correct, this seem to happen in the socket communication. I can see that your host resolves to IPv6. Did you maybe turn off IPv6 on your operating system?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.