How to Fix MySQL Error 1440 (ER_XAER_DUPID)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 1440 when a new distributed transaction reuses an active transaction ID. You fix this error by rolling back the stuck transaction or generating unique IDs. Distributed databases rely on two-phase commit protocols to keep data safe across nodes. MySQL tracks each distributed branch using a unique identifier called an XID. If an app tries to start a branch with an existing XID, MySQL blocks it. The server returns symbol ER_XAER_DUPID and SQLSTATE XAE08 with the message that th

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You get mysql error 1440 when a new distributed transaction reuses an active transaction ID. You fix this error by rolling back the stuck transaction or generating unique IDs.

Distributed databases rely on two-phase commit protocols to keep data safe across nodes. MySQL tracks each distributed branch using a unique identifier called an XID. If an app tries to start a branch with an existing XID, MySQL blocks it. The server returns symbol ER_XAER_DUPID and SQLSTATE XAE08 with the message that the XID already exists. This safeguard stops two processes from writing to the same transaction state at once.

What causes mysql error 1440 in your database

The most common cause is a poor ID generator in your transaction manager. If two app servers build IDs using simple counters, they often collide under load. Retry logic in your network layer can also trigger this specific failure. A client might lose its link right after starting a distributed transaction branch. The client then reconnects and sends the exact same start request a second time. MySQL still holds the first branch in memory, so it rejects the second attempt.

Abandoned transactions in a prepared state also cause this error during recovery runs. When a coordinator crashes, MySQL keeps the prepared branch locked until a manager resolves it. If a restarted coordinator reuses that old ID for new work, the database throws ER_XAER_DUPID. Connection pools can make this worse when they reset sessions without cleaning up open branches.

How to find and fix duplicate XIDs

First, you need to list all prepared transactions currently open on your MySQL server. Database admins run a recovery inspection query to read the active XIDs in memory. Compare these active IDs against the logs from your transaction manager or app servers. This step shows you whether the duplicate ID belongs to a live job or a dead session.

If the branch belongs to a dead session, you must close it cleanly. Decide with your team whether to commit or roll back the prepared work. Check the state of the other databases in the same global transaction first. Once you finish or roll back the stuck branch, MySQL frees that XID. Do not grant full admin rights to app roles just to clear stuck transactions. Limit recovery permissions to a dedicated ops role with strict audit logging.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to prevent duplicate transaction IDs

Update your transaction manager so it builds globally unique IDs for every single branch. Combine a node ID, a high-precision timestamp, and a random value in each XID. This simple pattern stops two app servers from picking the same ID at once.

You should also review how your connection pool handles broken network links. Set up the pool to test sessions and drop dirty links before reuse. Build your retry logic to check for existing branches before starting a new one. Good timeout rules on your coordinator will also clear dead branches before IDs repeat.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.

Frequently asked questions

What does ER_XAER_DUPID mean in MySQL?

ER_XAER_DUPID is the official symbol for MySQL error code 1440 and SQLSTATE XAE08. It means a client tried to start a distributed transaction with an existing XID.

Does a server restart clear prepared XA transactions?

No, MySQL saves prepared XA transactions to disk so they survive a server restart. You must explicitly commit or roll back the prepared branch to free the XID.

Can connection pooling cause mysql error 1440?

Yes, a pool can hand out a session that still holds an active branch. If the next app thread reuses the same ID scheme, the database rejects it.

The query runs. The emails stay hidden.