# org.apache.kafka.common.errors.TransactionTimeoutException: 事务已超时并被中止。

- **ID:** `kafka/transaction-aborted-due-to-timeout`
- **领域:** kafka
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

Kafka 事务性生产者在提交前超过了 `transaction.timeout.ms` 的限制，导致协调器中止了该事务。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kafka 2.5.0 | active | — | — |
| Kafka 3.1.0 | active | — | — |
| Kafka 3.5.0 | active | — | — |

## 解决方案

1. ```
   Increase `transaction.timeout.ms` in the producer config (e.g., `transaction.timeout.ms=120000`) to accommodate longer-running transactions, and ensure the commit logic completes within this window.
   ```
2. ```
   Optimize the transaction logic—e.g., reduce the number of partitions or messages per transaction, or use asynchronous commits where possible.
   ```

## 无效尝试

- **Setting `transaction.timeout.ms` to an extremely low value to speed up transactions** — A very low timeout increases the risk of aborts under normal load, making the system unstable. (80% 失败率)
- **Disabling idempotence to bypass transaction timeout checks** — Transactions require idempotence; disabling it will cause configuration errors and break transactional guarantees. (95% 失败率)
