JuliusBrussee/caveman · error

clickhouse response exceeds

Error message

clickhouse response exceeds %d byte limit

What it means

ReadBodyBounded reads one byte beyond maxBytes so it can distinguish an exactly-limit-sized body from a larger one. When the body exceeds the ceiling it returns this error and discards the data, refusing to parse or log potentially oversized/attacker-controlled content.

Solutions

  1. Raise the maxBytes limit to a value that fits your largest legitimate response.
  2. Constrain the query itself (LIMIT, narrower columns, aggregation) so results fit the ceiling.
  3. If oversize is expected, stream/process the body in chunks instead of ReadBodyBounded.
  4. Log the limit that was exceeded and the source URL to decide whether config or query is at fault.

Example fix

// before
body, err := chhttp.ReadBodyBounded(resp.Body, 1<<20) // 1 MiB, too small
// after
body, err := chhttp.ReadBodyBounded(resp.Body, 64<<20) // 64 MiB ceiling
Defensive patterns

Strategy: fallback

Validate before calling

if limit <= 0 { return fmt.Errorf("limit must be positive") }
// optionally probe Content-Length first:
if resp.ContentLength > limit {
    return fmt.Errorf("response of %d bytes exceeds limit %d", resp.ContentLength, limit)
}

Try / catch

body, err := chhttp.ReadBodyBounded(resp.Body, limit)
if err != nil {
    if strings.Contains(err.Error(), "exceeds") && strings.Contains(err.Error(), "byte limit") {
        // treat as hard rejection: don't parse body; narrow query or raise limit
        return fmt.Errorf("clickhouse response too large: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ReadBodyBounded on a ClickHouse HTTP response (or error body) whose size exceeds the configured maxBytes limit — e.g. a runaway query returning gigabytes against a small ceiling.

Common situations: A SELECT without LIMIT returning more rows than expected; maxBytes configured too small for legitimate large result sets; an error page from a proxy bigger than the assumed small error-body budget.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/be2a81dc81f2866c. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/chhttp/chhttp.go:56

const (
	defaultInsertTimeoutMS = 5000
	defaultQueryTimeoutMS  = 30000
)

// ReadBodyBounded reads an HTTP response/error body with a hard byte ceiling.
// It deliberately reads one byte beyond the limit so callers can distinguish a
// truncated body from an exact-limit body and fail closed before parsing or
// logging attacker-controlled content.
func ReadBodyBounded(r io.Reader, maxBytes int64) ([]byte, error) {
	if maxBytes <= 0 {
		return nil, fmt.Errorf("clickhouse response byte limit must be positive")
	}
	data, err := io.ReadAll(io.LimitReader(r, maxBytes+1))
	if err != nil {
		return nil, err
	}
	if int64(len(data)) > maxBytes {
		return nil, fmt.Errorf("clickhouse response exceeds %d byte limit", maxBytes)
	}
	return data, nil
}

// The TLS knobs. All three are unset by default, in which case the clients keep
// stock net/http behaviour: system roots, hostname verified against the URL host.
const (
	// serverNameEnv overrides tls.Config.ServerName. This is the managed-
	// ClickHouse cutover case: the private .internal DNS record is dialled while
	// the deployment's certificate carries only *.dtwh SANs, so verification must
	// run against the name the certificate actually holds. Chain AND hostname
	// verification stay fully enforced — only the name being matched changes.
	serverNameEnv = "CLICKHOUSE_TLS_SERVER_NAME"
	// caFileEnv is a path to a PEM bundle APPENDED to the system roots (a private
	// CA is trusted in addition to, never instead of, the public ones).
	caFileEnv = "CLICKHOUSE_TLS_CA_FILE"
	// skipVerifyEnv disables chain and hostname verification. Production refuses
	// it outright; outside production it is honoured with a startup warning.

View on GitHub (pinned to 3ee70a1026)