{"record":{"id":"5d88ff282bb6cdb0","repo":"vitessio/vitess","slug":"unexpected-result-d-from-connection-id-query","errorCode":null,"errorMessage":"unexpected result (%d) from connection_id() query, error: %v","messagePattern":"unexpected result \\((.+?)\\) from connection_id\\(\\) query, error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vreplication/vreplicator.go","lineNumber":983,"sourceCode":"\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}\n\n\t// This could take hours so we start a monitoring goroutine to\n\t// listen for the cancellations which indicate that the controller\n\t// is stopping: engine shutdown (tablet shutdown or transition) or","sourceCodeStart":965,"sourceCodeEnd":1001,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go#L965-L1001","documentation":"execPostCopyActions reads the single row from 'select connection_id()' and converts it to an int64. This error is thrown when the conversion fails (err != nil) or the value is 0, meaning MySQL returned something that is not a valid, non-zero connection identifier. It guards the later KILL <connID> logic against executing with a bogus ID.","triggerScenarios":"idqr.Rows[0][0].ToInt64() fails to parse the first cell of the connection_id() result, or parses to 0 — e.g. the column value is NULL, non-numeric, or a zero value due to a server/client anomaly.","commonSituations":"Corrupted or non-standard result from the MySQL server; a proxy or middleware altering the result set; essentially never seen with a direct, healthy MySQL connection.","solutions":["Retry the workflow so a new DB connection is created and the query re-executed","Check MySQL server logs and any intervening proxies for result-set tampering or protocol errors","Verify the tablet connects directly to MySQL (no unexpected result rewriting middleware)","If reproducible, capture the raw result and file a Vitess issue"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"idqr, err := dbClient.ExecuteFetch(\"select connection_id()\", 1)\nif err == nil && validSingleRowResult(idqr) {\n    if v, verr := idqr.Rows[0][0].ToInt64(); verr == nil && v > 0 {\n        // connID usable for KILL\n    }\n}","typeGuard":"func validConnID(qr *sqltypes.Result) (int64, bool) {\n    if qr == nil || len(qr.Rows) != 1 || len(qr.Rows[0]) == 0 {\n        return 0, false\n    }\n    id, err := qr.Rows[0][0].ToInt64()\n    if err != nil || id <= 0 {\n        return 0, false\n    }\n    return id, true\n}","tryCatchPattern":null,"preventionTips":["Ensure a direct, healthy MySQL connection (no result-rewriting middleware)","Keep MySQL server logs monitored for anomalies","Retry the workflow phase if the anomaly is transient","Report reproducible cases to Vitess with raw server logs"],"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"}