{"record":{"id":"f65af523d43ec932","repo":"bytebase/bytebase","slug":"failed-to-commit-execute-transaction","errorCode":null,"errorMessage":"failed to commit execute transaction","messagePattern":"failed to commit execute transaction","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/db/mysql/mysql.go","lineNumber":450,"sourceCode":"\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tallRowsAffected := sqlResult.(mysql.Result).AllRowsAffected()\n\t\t\tvar rowsAffected int64\n\t\t\tvar allRowsAffectedInt64 []int64\n\t\t\tfor _, a := range allRowsAffected {\n\t\t\t\trowsAffected += a\n\t\t\t\tallRowsAffectedInt64 = append(allRowsAffectedInt64, a)\n\t\t\t}\n\t\t\ttotalRowsAffected += rowsAffected\n\n\t\t\topts.LogCommandResponse(rowsAffected, allRowsAffectedInt64, \"\")\n\t\t}\n\n\t\tif err := tx.Commit(); err != nil {\n\t\t\topts.LogTransactionControl(storepb.TaskRunLog_TransactionControl_COMMIT, err.Error())\n\t\t\treturn errors.Wrapf(err, \"failed to commit execute transaction\")\n\t\t} else {\n\t\t\topts.LogTransactionControl(storepb.TaskRunLog_TransactionControl_COMMIT, \"\")\n\t\t\tcommitted = true\n\t\t}\n\t\treturn nil\n\t}); err != nil {\n\t\treturn 0, err\n\t}\n\n\treturn totalRowsAffected, nil\n}\n\n// executeInAutoCommitMode executes statements sequentially in auto-commit mode\nfunc (d *Driver) executeInAutoCommitMode(ctx context.Context, conn *sql.Conn, commands []base.Statement, opts db.ExecuteOptions, connectionID string) (int64, error) {\n\tvar totalRowsAffected int64\n\n\tif err := conn.Raw(func(driverConn any) error {\n\t\t//nolint","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/db/mysql/mysql.go#L432-L468","documentation":"When Execute runs statements inside an explicit transaction, tx.Commit() must succeed to persist the work. If the driver returns an error on commit (connection dropped, deadlock/timeout, server shutdown), the error is wrapped as 'failed to commit execute transaction' and surfaced to the caller; nothing from the transaction is persisted.","triggerScenarios":"tx.Commit() fails during Execute's transactional path — typically because the MySQL connection was lost mid-transaction, the server killed the transaction (lock wait timeout, deadlock), or the session was terminated.","commonSituations":"Long-running migrations exceeding wait_timeout; network blips between app and database; lock contention with other writers causing implicit rollback before commit; admin killing the connection.","solutions":["Re-run the task; if the transaction failed nothing was committed, so a retry is safe","Check server logs for the underlying commit error (deadlock, lock wait timeout, connection killed)","Increase lock_wait_timeout / innodb_lock_wait_timeout or reduce contention","Check network stability and idle timeouts (wait_timeout) between client and MySQL"],"exampleFix":"// before\nif err := tx.Commit(); err != nil {\n  return errors.Wrapf(err, \"failed to commit execute transaction\")\n}\n// after\nif err := tx.Commit(); err != nil {\n  if mysqlErr, ok := errors.Unwrap(err).(*mysqldriver.MySQLError); ok && isRetryable(mysqlErr) {\n    return retryable(err) // let the task runner retry the whole transaction\n  }\n  return errors.Wrapf(err, \"failed to commit execute transaction\")\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := executeTransaction(ctx, stmts)\nif err != nil && strings.Contains(err.Error(), \"failed to commit execute transaction\") {\n  // transaction rolled back on commit failure; safe to retry whole unit\n  return retryWithBackoff(executeTransaction, ctx, stmts)\n}","preventionTips":["Keep transactions short to avoid lock wait timeouts and connection kills","Raise innodb_lock_wait_timeout if contention is expected","Monitor wait_timeout and keep-alive settings on the connection pool","Check MySQL error log for deadlock/kill events after a failed commit"],"tags":["mysql","transaction","commit","network"],"backgroundTag":"database-write-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}