googleapis/mcp-toolbox · error

errors encountered during row iteration: %w

Error message

errors encountered during row iteration: %w

What it means

This error wraps the result of rows.Err() after the row loop in the MySQL RunSQL tool. It signals that the result-set iteration ended abnormally — the underlying connection experienced an error mid-stream (network drop, server killed the connection, context canceled) rather than reaching a clean end of rows.

Source

Thrown at internal/sources/mysql/mysql.go:180

		row := orderedmap.Row{}
		for i, name := range cols {
			val := rawValues[i]
			if val == nil {
				row.Add(name, nil)
				continue
			}

			convertedValue, err := mysqlcommon.ConvertToType(colTypes[i], val)
			if err != nil {
				return nil, fmt.Errorf("errors encountered when converting values: %w", err)
			}
			row.Add(name, convertedValue)
		}
		out = append(out, row)
	}

	if err := results.Err(); err != nil {
		return nil, fmt.Errorf("errors encountered during row iteration: %w", err)
	}

	return out, nil
}

func initMySQLConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string, queryParams map[string]string) (*sql.DB, error) {
	//nolint:all // Reassigned ctx
	ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
	defer span.End()

	config := driver.NewConfig()
	config.Addr = fmt.Sprintf("%s:%s", host, port)
	config.Net = "tcp"
	if user != "" {
		config.User = user
		// password will require user
		if pass != "" {
			config.Passwd = pass

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Re-run the query; transient network drops often succeed on retry.
  2. Reduce result set size with LIMIT/pagination so rows stream within connection timeouts.
  3. Increase relevant timeouts (server net_read_timeout/net_write_timeout, client ReadTimeout, proxy idle timeouts).
  4. Check server logs for aborted connections and enable TCP keepalives in the DSN (e.g. timeout/readTimeout params).
Defensive patterns

Strategy: retry

Try / catch

var out any
err := retry.Do(func() error {
    var invokeErr error
    out, invokeErr = toolboxClient.InvokeTool(ctx, "run-sql", params)
    if invokeErr != nil && strings.Contains(invokeErr.Error(), "errors encountered during row iteration") {
        return invokeErr // transient network/stream error: retry
    }
    return nil // do not retry other errors
}, retry.Attempts(3), retry.Delay(2*time.Second), retry.OnRetry(func(n uint, err error) {
    log.Printf("row iteration interrupted, retry %d: %v", n+1, err)
}))

Prevention

When it happens

Trigger: A large result set iteration interrupted by a network interruption, a MySQL server timeout (wait_timeout, net_write_timeout), the query context being canceled, or the server closing the connection while rows were still streaming.

Common situations: Long-running queries over flaky networks, results larger than available memory/buffers behind proxies (e.g. Cloud SQL proxy, load balancers with idle timeouts), and Docker/NAT connections reaped mid-query.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/0d6b9203f8727755. Report an issue: GitHub.