{"record":{"id":"aa56f9dcfa718232","repo":"googleapis/mcp-toolbox","slug":"errors-encountered-during-row-iteration-w-aa56f9","errorCode":null,"errorMessage":"errors encountered during row iteration: %w","messagePattern":"errors encountered during row iteration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/trino/trino.go","lineNumber":160,"sourceCode":"\t\tfor i, name := range cols {\n\t\t\tval := rawValues[i]\n\t\t\tif val == nil {\n\t\t\t\tvMap[name] = nil\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Convert byte arrays to strings for text fields\n\t\t\tif b, ok := val.([]byte); ok {\n\t\t\t\tvMap[name] = string(b)\n\t\t\t} else {\n\t\t\t\tvMap[name] = val\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 during row iteration: %w\", err)\n\t}\n\n\treturn out, nil\n}\n\nfunc initTrinoConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, password, catalog, schema, queryTimeout, accessToken string, kerberosEnabled, sslEnabled bool, sslCertPath, sslCert string, disableSslVerification bool) (*sql.DB, error) {\n\t//nolint:all // Reassigned ctx\n\tctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)\n\tdefer span.End()\n\n\t// Build Trino DSN\n\tdsn, err := buildTrinoDSN(host, port, user, password, catalog, schema, queryTimeout, accessToken, kerberosEnabled, sslEnabled, sslCertPath, sslCert)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to build DSN: %w\", err)\n\t}\n\n\tlogger, err := util.LoggerFromContext(ctx)\n\tif err != nil {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/trino/trino.go#L142-L178","documentation":"Trino RunSQL checks results.Err() after the row loop and wraps any deferred iteration error. Errors that occur partway through streaming rows (HTTP stream interruptions, coordinator query termination, context cancellation) surface here rather than at Scan time. The driver error is preserved via %w.","triggerScenarios":"Source.RunSQL where results.Err() is non-nil after iteration: Trino query killed (e.g. exceeded query.max-memory or execution timeout), HTTP stream dropped mid-transfer, or ctx cancelled while rows streamed.","commonSituations":"Large scans exceeding Trino memory limits or query.max-run-time; LB/proxy idle timeouts cutting the streaming HTTP response; client-side request timeouts on big exports.","solutions":["Increase queryTimeout and the caller's context deadline for large results","Check the wrapped error for a Trino query ID and inspect coordinator logs for the kill reason","Tune Trino session properties (query.max-memory, query.max-execution-time) or paginate with LIMIT/OFFSET","Check proxy/LB read timeouts vs query duration"],"exampleFix":"// before\nrows, err := db.QueryContext(ctx, \"SELECT * FROM huge_table\")\n// after\nrows, err := db.QueryContext(ctx, \"SELECT * FROM huge_table LIMIT 10000 OFFSET 0\")","handlingStrategy":"retry","validationCode":"// set generous deadline before large scans\nctx, cancel := context.WithTimeout(ctx, 10*time.Minute)\ndefer cancel()","typeGuard":null,"tryCatchPattern":"out, err := src.RunSQL(ctx, stmt, params)\nif err != nil && strings.Contains(err.Error(), \"errors encountered during row iteration\") {\n    if errors.Is(err, context.DeadlineExceeded) {\n        // paginate instead of retrying the same oversized query\n        out, err = runPaginated(ctx, stmt, 10000)\n    }\n}","preventionTips":["Paginate large result sets with LIMIT/OFFSET","Raise queryTimeout and caller context deadlines together","Tune Trino query.max-memory / max-execution-time for analytical scans","Set proxy/LB read timeouts above the longest expected query"],"tags":["database","trino","row-iteration","query-timeout"],"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"}