{"record":{"id":"bc8f8ed9257d6c75","repo":"vitessio/vitess","slug":"unexpected-number-of-rows-returned-d-from-conne","errorCode":null,"errorMessage":"unexpected number of rows returned (%d) from connection_id() query","messagePattern":"unexpected number of rows returned \\((.+?)\\) from connection_id\\(\\) query","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vreplication/vreplicator.go","lineNumber":979,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\t// qr should never be nil, but check anyway to be extra safe.\n\tif qr == nil || len(qr.Rows) == 0 {\n\t\treturn nil\n\t}\n\n\tvr.insertLog(LogCopyStart, fmt.Sprintf(\"Executing %d post copy action(s) for %s table\", len(qr.Rows), tableName))\n\n\t// Save our connection ID so we can use it to easily KILL any\n\t// running SQL action we may perform later if needed.\n\tidqr, err := dbClient.ExecuteFetch(\"select connection_id()\", 1)\n\tif err != nil {\n\t\treturn err\n\t}\n\t// qr should never be nil, but check anyway to be extra safe.\n\tif idqr == nil || len(idqr.Rows) != 1 {\n\t\treturn fmt.Errorf(\"unexpected number of rows returned (%d) from connection_id() query\", len(idqr.Rows))\n\t}\n\tconnID, err := idqr.Rows[0][0].ToInt64()\n\tif err != nil || connID == 0 {\n\t\treturn fmt.Errorf(\"unexpected result (%d) from connection_id() query, error: %v\", connID, err)\n\t}\n\n\tdeleteAction := func(dbc *vdbClient, id int64, vid int32, tn string) error {\n\t\tdelq, err := sqlparser.ParseAndBind(sqlDeletePostCopyAction, sqltypes.Int32BindVariable(vid),\n\t\t\tsqltypes.StringBindVariable(tn), sqltypes.Int64BindVariable(id))\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif _, err := dbc.ExecuteFetch(delq, 1); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to delete post copy action for the %q table with id %d: %v\",\n\t\t\t\ttableName, id, err)\n\t\t}\n\t\treturn nil\n\t}","sourceCodeStart":961,"sourceCodeEnd":997,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go#L961-L997","documentation":"After copying a table, execPostCopyActions runs 'select connection_id()' on its own DB client to record the connection so it can be KILLed if the workflow is interrupted. This error is thrown when the query returns a result set with anything other than exactly one row (or a nil result), which the connection_id() function should never do. It is a defensive check against an unexpected server/client behavior.","triggerScenarios":"execPostCopyActions (invoked via copyTable / runPostCopyActionsAndDeleteCopyActions) executes 'select connection_id()' and the returned *sqltypes.Result is nil or len(idqr.Rows) != 1 — e.g. the underlying MySQL connection returned a corrupted or empty result.","commonSituations":"MySQL server misbehaving or an incompatibility in the MySQL/vitess client stack returning empty results; transient connection state corruption; this should essentially never occur in healthy deployments.","solutions":["Retry the workflow — the copy phase restarts and re-establishes a fresh connection","Check MySQL server health and error logs for connection or protocol errors around the time of the failure","Verify the tablet's MySQL version is supported by this Vitess release","If reproducible, file a Vitess issue with tablet and MySQL logs"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"idqr, err := dbClient.ExecuteFetch(\"select connection_id()\", 1)\nif err == nil && idqr != nil && len(idqr.Rows) == 1 {\n    if v, verr := idqr.Rows[0][0].ToInt64(); verr == nil && v > 0 { /* connection healthy */ }\n}","typeGuard":"func validSingleRowResult(qr *sqltypes.Result) bool {\n    return qr != nil && len(qr.Rows) == 1 && len(qr.Rows[0]) > 0\n}","tryCatchPattern":"if err != nil || idqr == nil || len(idqr.Rows) != 1 {\n    // treat as transient server anomaly: reconnect and retry the phase\n    return retryWorkflowPhase()\n}","preventionTips":["Monitor MySQL server logs for protocol/connection anomalies on the tablet host","Keep MySQL and Vitess on supported, compatible versions","Avoid proxies/middleware between vttablet and mysqld that could alter result sets","On occurrence, restart the workflow — the copy phase reconnects cleanly"],"tags":["vreplication","mysql","go"],"backgroundTag":"unexpected-query-result","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}