kenpritchard opened a new pull request, #552: URL: https://github.com/apache/commons-dbcp/pull/552
Fixes [DBCP-601](https://issues.apache.org/jira/browse/DBCP-601). `LocalXAConnectionFactory.LocalXAResource.prepare()` returns `XA_RDONLY` for a read-only connection but leaves `currentXid` set. A resource that votes `XA_RDONLY` takes no part in phase 2, so the transaction manager never calls `commit()` or `rollback()`, which are the only places `currentXid` was cleared. The pooled connection goes back to the pool still associated with a completed transaction, and the next transaction that borrows it fails in `start()` with `Already enlisted in another transaction`. ### Change One line on the read-only path in `prepare()`: clear `currentXid` before returning `XA_RDONLY`. It still returns `XA_RDONLY`, so the transaction manager skips phase 2 as before. Read-write two-phase commit, one-phase commit and rollback are unchanged. ### Tests - `TestLocalXaResource.testPrepareReadOnlyEndsTransactionBranch`: after a read-only `prepare()`, `getXid()` is `null` and a new branch can `start()`. - `TestLocalXaResource.testPrepareReadWriteKeepsTransactionBranch`: a read-write `prepare()` still keeps the association (passes before and after; guards the read-write path). - `TestBasicManagedDataSource.testReadOnlyConnectionReusableAfterTwoPhaseCommit`: with the Geronimo TM and `maxTotal=1`, a read-only connection plus a second XA resource commits through two-phase commit, and the next transaction can enlist the same pooled connection. On current `master` the first and third tests fail (`expected: <null> but was: <TestXid...>` and `XAException: Already enlisted in another transaction`); with the fix both pass. A plain `mvn` (all checks, 1608 tests) passes locally on Java 21. I also added a `changes.xml` entry under 2.14.1 FIX. ### Checklist - [x] Read the contribution guidelines for this project. - [x] Read the ASF Generative Tooling Guidance. - [x] I used AI to create any part of, or all of, this pull request. **AI disclosure:** I used Claude Opus 5.5 (Anthropic), through Hermes Agent, to help trace the bug, write the reproduction and the tests, and draft this description. I reviewed every line, ran the tests before and after the fix, and the change is mine to contribute under the Apache License. The commit carries an `Assisted-By:` trailer. - [x] Run a successful build using the default Maven goal with `mvn`. - [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [x] Each commit in the pull request has a meaningful subject line and body. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
