googleapis/mcp-toolbox · error
errors encountered during row iteration: %w
Error message
errors encountered during row iteration: %w
What it means
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.
Source
Thrown at internal/sources/trino/trino.go:160
for i, name := range cols {
val := rawValues[i]
if val == nil {
vMap[name] = nil
continue
}
// Convert byte arrays to strings for text fields
if b, ok := val.([]byte); ok {
vMap[name] = string(b)
} else {
vMap[name] = val
}
}
out = append(out, vMap)
}
if err := results.Err(); err != nil {
return nil, fmt.Errorf("errors encountered during row iteration: %w", err)
}
return out, nil
}
func 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) {
//nolint:all // Reassigned ctx
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
defer span.End()
// Build Trino DSN
dsn, err := buildTrinoDSN(host, port, user, password, catalog, schema, queryTimeout, accessToken, kerberosEnabled, sslEnabled, sslCertPath, sslCert)
if err != nil {
return nil, fmt.Errorf("failed to build DSN: %w", err)
}
logger, err := util.LoggerFromContext(ctx)
if err != nil {View on GitHub (pinned to 8cc6e09de2)
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
Example fix
// before rows, err := db.QueryContext(ctx, "SELECT * FROM huge_table") // after rows, err := db.QueryContext(ctx, "SELECT * FROM huge_table LIMIT 10000 OFFSET 0")
Defensive patterns
Strategy: retry
Validate before calling
// set generous deadline before large scans ctx, cancel := context.WithTimeout(ctx, 10*time.Minute) defer cancel()
Try / catch
out, err := src.RunSQL(ctx, stmt, params)
if err != nil && strings.Contains(err.Error(), "errors encountered during row iteration") {
if errors.Is(err, context.DeadlineExceeded) {
// paginate instead of retrying the same oversized query
out, err = runPaginated(ctx, stmt, 10000)
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unable to retrieve column names: %w
- errors encountered during row iteration: %w
- errors encountered during row iteration: %w
- unable to create pool: %w
- unable to connect successfully: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/aa56f9dcfa718232.
Report an issue: GitHub.