juicedata/juicefs · error

error creating GET request: %v

Error message

error creating GET request: %v

What it means

getRequest in cmd/debug.go builds an http GET with a context timeout via http.NewRequestWithContext. Errors returned at request-construction time (invalid method, unparsable/invalid URL per net/url.Parse, or a nil context/body misuse) are wrapped as 'error creating GET request: %v'. Unlike the later 'error GET request' case, the request never reached the network — it failed to be created.

Source

Thrown at cmd/debug.go:227

					listenPort = port
				}
				continue
			}
		}
	}

	if listenPort == -1 {
		return 0, fmt.Errorf("no valid pprof port found")
	}
	return listenPort, nil
}

func getRequest(url string, timeout time.Duration) ([]byte, error) {
	ctx, cancel := context.WithTimeout(context.Background(), timeout)
	defer cancel()
	req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
	if err != nil {
		return nil, fmt.Errorf("error creating GET request: %v", err)
	}
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, fmt.Errorf("error GET request: %v", err)
	}
	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("error GET request, status code %d", resp.StatusCode)
	}

	defer func(body io.ReadCloser) {
		if err := body.Close(); err != nil {
			logger.Errorf("error closing body: %v", err)
		}
	}(resp.Body)
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("error reading response: %v", err)
	}

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Log/inspect the exact url value passed in; validate it with url.Parse before calling getRequest.
  2. Fix the port discovery path so checkPort is only called with a valid 6060-6099 port (see error 165/166).
  3. Verify configured metric URLs in reqAndSaveMetric are absolute http(s) URLs with no stray whitespace or unescaped characters.

Example fix

// before
u := fmt.Sprintf("http://localhost:%d/debug/pprof/cmdline?debug=1", port)
resp, err := getRequest(u, 3*time.Second)
// after
if _, err := url.Parse(u); err != nil {
    return fmt.Errorf("invalid pprof url %q: %v", u, err)
}
resp, err := getRequest(u, 3*time.Second)
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(rawURL)
if err != nil || u.Scheme == "" || u.Host == "" {
    return fmt.Errorf("invalid URL %q: %v", rawURL, err)
}

Try / catch

body, err := getRequest(url, timeout)
if err != nil {
    if strings.Contains(err.Error(), "error creating GET request") {
        logger.Errorf("malformed url %q: %v", url, err) // fix url, retrying won't help
        return err
    }
}

Prevention

When it happens

Trigger: Called from checkPort with `http://localhost:<port>/debug/pprof/cmdline?debug=1` and from reqAndSaveMetric with a metric URL; the error fires only when `http.NewRequestWithContext` returns err — practically always a malformed URL string such as an empty URL, control characters, or an invalid port in the host part.

Common situations: A port parsed from lsof output is 0 or garbage and gets interpolated into the URL template; a metric URL configured/constructed with unescaped characters; an empty metric.url passed to reqAndSaveMetric.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/5e24c675bcb9c19e. Report an issue: GitHub.