Common SQL Errors

MySQL Error 1402: ER_XA_RBROLLBACK - Causes, Fixes, and Prevention

Galaxy Team
August 7, 2025

<p>ER_XA_RBROLLBACK signals that the resource manager asked MySQL to roll back a prepared XA transaction branch instead of committing it.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1402 ER_XA_RBROLLBACK?

<p>MySQL Error 1402: ER_XA_RBROLLBACK means the resource manager rolled back an XA transaction branch, often due to timeouts or deadlocks. Clear the XA record with XA ROLLBACK and replay the logical work to resolve the issue.</p>

Error Highlights

Typical Error Message

XA_RBROLLBACK: Transaction branch was rolled back

Error Type

Transaction Error

Language

MySQL

Symbol

ER_XA_RBROLLBACK

Error Code

1402

SQL State

XA100

Explanation

Table of Contents

What is MySQL Error 1402 ER_XA_RBROLLBACK?

Error 1402 occurs during distributed XA transactions when a resource manager (RM) tells MySQL that a prepared branch must be rolled back. MySQL records this outcome with the ER_XA_RBROLLBACK condition and SQLSTATE XA100.

The message appears after XA PREPARE but before XA COMMIT, indicating that a two-phase commit could not finish successfully. Only the affected branch is reversed; other branches may still commit or roll back separately.

What Causes This Error?

The RM may detect a deadlock, timeout, or integrity violation and decide the safest action is to undo the branch. Network issues, crashed nodes, or manual administrator intervention can also trigger the rollback reply.

Because XA uses a global transaction ID (XID), any participant that votes to roll back forces the coordinator to roll back the entire global transaction.

How to Fix MySQL Error 1402 ER_XA_RBROLLBACK

First, clear lingering XA records with XA RECOVER and XA ROLLBACK. Then replay the lost logical work in a new, healthy XA transaction. Verify that all RMs are reachable before issuing XA PREPARE again.

If the error repeats, investigate the RM logs for deeper issues such as missing indexes, lock scarcity, or configuration mismatches.

Common Scenarios and Solutions

Timeout during long-running batch: shorten batch size or raise innodb_lock_wait_timeout. Deadlock between branches: revise access order or use READ COMMITTED isolation. Resource exhaustion: tune buffer pool and log file sizes.

Manual rollback from another system: coordinate commits with a global transaction manager or middleware that supports two-phase commit.

Best Practices to Avoid This Error

Keep XA branches short and idempotent. Monitor XA RECOVER output for stray XIDs. Configure uniform isolation levels across participants. Use a proven transaction coordinator when multiple databases are involved.

Galaxy users can script health checks and share endorsed recovery queries, ensuring team-wide consistency and faster incident response.

Related Errors and Solutions

Error 1397 ER_XAER_RMFAIL happens when the RM is unavailable. Error 1398 ER_XAER_NOTA shows when an XID does not exist. Both require XA ROLLBACK or coordinator cleanup.

Common Causes

Resource manager timeout

When an RM exceeds its configured timeout, it aborts the branch to free locks, leading to ER_XA_RBROLLBACK.

Deadlock detection

If the RM detects a cyclic wait, it resolves the deadlock by rolling back one branch and signalling the error.

Integrity constraint violation

Unique key or foreign key violations during prepare force the RM to vote rollback.

Network partition or crash

A lost connection during prepare may cause the RM to roll back automatically when it comes back online.

Manual administrator intervention

Admins can cancel a prepared branch, which surfaces as ER_XA_RBROLLBACK on the coordinator.

Related Errors

ER_XAER_RMFAIL (1397)

The resource manager is unavailable or shut down. Restart the RM and rollback or replay the XA branch.

ER_XAER_NOTA (1398)

The provided XID is unknown. Ensure you pass the exact identifier returned by XA START.

ER_XAER_INVAL (1399)

Invalid arguments in an XA statement. Check XID format and statement order.

ER_XA_RETRY (1400)

Temporary failure. Retry the XA statement after resolving the underlying issue.

FAQs

Does ER_XA_RBROLLBACK always roll back the entire global transaction?

Yes. In two-phase commit, a single rollback vote forces the coordinator to undo the global transaction.

Can I force commit after receiving the error?

No. Once a participant votes rollback, the global transaction must be rolled back. Replay the business logic in a new XA cycle.

How do I find uncommitted XA branches?

Run XA RECOVER to list prepared branches. Clean them up with XA COMMIT or XA ROLLBACK as appropriate.

How does Galaxy help?

Galaxy lets teams store and share vetted XA recovery scripts, reducing response time and preventing manual mistakes.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo