glanceapp/glance · error

reading authentication response: %v

Error message

reading authentication response: %v

What it means

Returned by fetchPiholeSessionID when io.ReadAll(response.Body) fails while reading the auth response body. Rare: the request succeeded and headers were received, but the stream aborted mid-body — connection reset during transfer, premature close, or a read timeout.

Source

Thrown at internal/glance/widget-dns-stats.go:635

func fetchPiholeSessionID(instanceURL string, client *http.Client, password string) (string, error) {
	requestBody := []byte(`{"password":"` + password + `"}`)

	request, err := http.NewRequest("POST", instanceURL+"/api/auth", bytes.NewBuffer(requestBody))
	if err != nil {
		return "", fmt.Errorf("creating authentication request: %v", err)
	}
	request.Header.Set("Content-Type", "application/json")

	response, err := client.Do(request)
	if err != nil {
		return "", fmt.Errorf("sending authentication request: %v", err)
	}
	defer response.Body.Close()

	body, err := io.ReadAll(response.Body)
	if err != nil {
		return "", fmt.Errorf("reading authentication response: %v", err)
	}

	var jsonResponse struct {
		Session struct {
			SID     string `json:"sid"`
			Message string `json:"message"`
		} `json:"session"`
	}

	if err := json.Unmarshal(body, &jsonResponse); err != nil {
		return "", fmt.Errorf("parsing authentication response: %v", err)
	}

	if response.StatusCode != http.StatusOK {
		return "", fmt.Errorf(
			"authentication request returned status %s with message '%s'",
			response.Status, jsonResponse.Session.Message,
		)

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Retry — transient mid-body failures usually clear on the next widget refresh.
  2. If persistent, capture whether a proxy between glance and Pi-hole truncates responses.
  3. Increase client timeouts if the Pi-hole host is slow (high load).
  4. Verify with a large curl of the same endpoint that the body transfers fully.
Defensive patterns

Strategy: retry

Try / catch

if err != nil && strings.Contains(err.Error(), "reading authentication response") {
    // mid-body abort: almost always transient — rely on the next refresh
    slog.Warn("pihole auth body read failed, will retry", "error", err)
}

Prevention

When it happens

Trigger: Upstream or an intermediary proxy closes the connection before Content-Length bytes arrive; client read timeout shorter than the server's response time; connection reset by a firewall or load balancer.

Common situations: Flaky Wi-Fi/VPN link to a self-hosted Pi-hole; aggressive proxy idle timeouts; Pi-hole restarting exactly while responding.

Understand the failure class

Related errors


AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15). Data as JSON: /api/errors/7802ddc8a08b4764. Report an issue: GitHub.