{"record":{"id":"c2614f583d3ce087","repo":"googleapis/mcp-toolbox","slug":"errors-encountered-by-results-scan-w","errorCode":null,"errorMessage":"errors encountered by results.Scan: %w","messagePattern":"errors encountered by results\\.Scan: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/clickhouse/clickhouse.go","lineNumber":165,"sourceCode":"\t\t\t\tif rawValues[i] != nil {\n\t\t\t\t\t// Handle potential []byte to string conversion if needed\n\t\t\t\t\tif b, ok := rawValues[i].([]byte); ok {\n\t\t\t\t\t\tvMap[name] = string(b)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvMap[name] = rawValues[i]\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tvMap[name] = nil\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\tvMap[name] = rawValues[i]\n\t\t\t}\n\t\t}\n\t\tout = append(out, vMap)\n\t}\n\n\tif err := results.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"errors encountered by results.Scan: %w\", err)\n\t}\n\n\treturn out, nil\n}\n\nfunc validateConfig(protocol string) error {\n\tvalidProtocols := map[string]bool{\"http\": true, \"https\": true}\n\n\tif protocol != \"\" && !validProtocols[protocol] {\n\t\treturn fmt.Errorf(\"invalid protocol: %s, must be one of: http, https\", protocol)\n\t}\n\treturn nil\n}\n\nfunc initClickHouseConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, protocol string, secure bool) (*sql.DB, error) {\n\t//nolint:all // Reassigned ctx\n\tctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)\n\tdefer span.End()","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/clickhouse/clickhouse.go#L147-L183","documentation":"Wraps any error returned by sql.Rows.Err() after all rows of a ClickHouse query have been iterated in RunSQL. It indicates the row iteration terminated abnormally — a connection drop, query cancellation, or driver-level failure encountered mid-scan — rather than a per-row scan error. The library surfaces it after processing whatever partial rows it could collect.","triggerScenarios":"Calling run_sql against a ClickHouse instance where the HTTP/HTTPS connection drops mid-result-stream, the context is cancelled while rows are being consumed, or the clickhouse driver returns an error after the last row.","commonSituations":"Long-running analytical queries timing out, ClickHouse server restarting under load, network proxies killing idle HTTP keep-alive connections during large result sets.","solutions":["Re-run the query; transient connection drops usually resolve on retry","Check ClickHouse server logs for query errors or restarts during execution","Verify network stability between toolbox and ClickHouse, especially proxy/load-balancer idle timeouts","Reduce result set size (LIMIT, pagination) to shorten streaming time","Ensure the parent context is not cancelled while the query runs"],"exampleFix":"// before\nout, err := source.RunSQL(ctx, \"SELECT * FROM huge_table\")\n// after\nctx, cancel := context.WithTimeout(ctx, 5*time.Minute)\ndefer cancel()\nout, err := source.RunSQL(ctx, \"SELECT id, ts, value FROM huge_table WHERE ts > now() - INTERVAL 1 DAY\")","handlingStrategy":"retry","validationCode":"// pre-check connectivity\nimport \"database/sql\"\nfunc pingCH(db *sql.DB) error { return db.PingContext(context.Background()) }","typeGuard":null,"tryCatchPattern":"// Go: inspect wrapped error and retry transient failures\nfor i := 0; i < 3; i++ {\n    out, err := src.RunSQL(ctx, q)\n    if err == nil { break }\n    var netErr net.Error\n    if errors.As(err, &netErr) || errors.Is(err, context.Canceled) {\n        time.Sleep(time.Duration(i+1) * time.Second)\n        continue\n    }\n    return err\n}","preventionTips":["Set generous context timeouts for large analytical queries","Add LIMIT/pagination to avoid huge streaming result sets","Monitor ClickHouse server availability and restarts","Configure proxy/load-balancer idle timeouts above query duration"],"tags":["clickhouse","database","connection-drop","query-execution"],"backgroundTag":"rows-iteration-error","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}