{"record":{"id":"50eb7c52cf4b4ad3","repo":"JuliusBrussee/caveman","slug":"s-w","errorCode":null,"errorMessage":"%s: %w","messagePattern":"%s: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/chhttp/chhttp.go","lineNumber":151,"sourceCode":"\t\t// warned about by ValidateProduction at startup.\n\t\tInsecureSkipVerify: skipVerify,\n\t}\n\tif caFile != \"\" {\n\t\troots, err := rootsWithCAFile(caFile)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tcfg.RootCAs = roots\n\t}\n\treturn cfg, nil\n}\n\n// rootsWithCAFile returns the system pool with the PEM bundle at path appended,\n// failing CLOSED on any unusable or truncated block (see cabundle.Pool).\nfunc rootsWithCAFile(path string) (*x509.CertPool, error) {\n\troots, err := cabundle.Pool(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", caFileEnv, err)\n\t}\n\treturn roots, nil\n}\n\n// errTransport fails every request with the configuration error that produced\n// it. A client constructor cannot return an error, and falling back to the\n// default transport would silently trade a rejected TLS configuration for\n// unpinned verification — so the client is built, and refuses to send.\ntype errTransport struct{ err error }\n\nfunc (t errTransport) RoundTrip(*http.Request) (*http.Response, error) { return nil, t.err }\n\n// queryTransport is the shared connection pool behind ClickHouse query clients.\n//\n// http.DefaultTransport keeps only DefaultMaxIdleConnsPerHost (2) idle\n// connections per host, so the 3rd+ concurrent ClickHouse read dials a fresh\n// connection and throws it away on completion — paying a TCP + TLS handshake per\n// query. Report handlers fan several queries out at once and production reads","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/chhttp/chhttp.go#L133-L169","documentation":"rootsWithCAFile wraps any error from cabundle.Pool when loading the CA-file env var's PEM bundle, prefixing it with the env var name. The bundle is loaded fail-closed: unreadable, malformed, or truncated PEM blocks abort configuration instead of silently degrading to the system pool.","triggerScenarios":"Calling tlsClientConfig (via client construction or ValidateProduction) with the CA-file env var set to a path that doesn't exist, isn't readable, or contains invalid/truncated PEM.","commonSituations":"Typo in the CA file path; the secret/configmap not mounted in the container; the bundle exported as DER instead of PEM; a truncated file from an interrupted copy; wrong file mounted at the expected path.","solutions":["Check the wrapped cabundle.Pool error (after the '%s: ' prefix) for the root cause: missing file, permission, or parse failure.","Verify the path in the CA-file env var exists and is readable inside the container/host (ls -l, cat the first lines).","Ensure the file is a valid PEM bundle (-----BEGIN CERTIFICATE----- blocks, complete, not DER).","Re-deploy/remount the secret or configmap if the file is missing in the runtime environment."],"exampleFix":"// before\nCLICKHOUSE_CA_FILE=/etc/certs/internal-ca.crt   // file never mounted\n// after\nCLICKHOUSE_CA_FILE=/etc/certs/internal-ca.pem   // valid PEM bundle, mounted\n// or in code, fail fast at boot:\nif _, err := chhttp.ValidateProduction(logger); err != nil {\n    logger.Error(\"clickhouse tls config invalid\", \"err\", err)\n    os.Exit(1)\n}","handlingStrategy":"validation","validationCode":"if path := strings.TrimSpace(os.Getenv(\"CLICKHOUSE_CA_FILE\")); path != \"\" {\n    if _, err := os.Stat(path); err != nil {\n        return fmt.Errorf(\"CLICKHOUSE_CA_FILE unreadable: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := chhttp.ValidateProduction(logger); err != nil {\n    if strings.Contains(err.Error(), caFileEnv) {\n        logger.Error(\"CA bundle unusable — check path, mounting, and PEM validity\", \"err\", err)\n        os.Exit(1)\n    }\n    return err\n}","preventionTips":["Verify CA bundle paths exist and are readable inside the container image at build time.","Keep bundles in PEM format; convert DER certs before mounting.","Check secret/configmap mounts in deploy manifests when this error appears only in-cluster."],"tags":["tls","certificate","clickhouse","ca-bundle"],"backgroundTag":"file-not-found","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}