Skip to content

ARTEMIS-6360 A second send of a duplicate id in the same transaction is a duplicate - #6884

Open
grepjava wants to merge 1 commit into
apache:mainfrom
grepjava:ARTEMIS-6360
Open

grepjava wants to merge 1 commit into
apache:mainfrom
grepjava:ARTEMIS-6360

Conversation

@grepjava

@grepjava grepjava commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

PostOfficeImpl.checkNotBridgeDuplicateID checked each send against cache.contains only. In a client transaction the id is not in the cache yet: addToCache(duplID, tx, false) adds it after the commit, so that a client resending a transaction after a failure is not rejected. A second send of the same id in the same transaction therefore passed the check too, and the commit delivered both messages (and added the id to the cache twice, see ARTEMIS-6361).

The ids a transaction sends are now kept in the transaction, by cache, and a send whose id the transaction already sent is a duplicate: the transaction is marked rollback-only, as for an id already in the cache. Other transactions do not see them, so a resent transaction is still accepted.

DuplicateDetectionTest.testSameIdTwiceInOneTransaction sends two messages with the same id in one transaction, expects the commit to fail with ActiveMQDuplicateIdException and no message to arrive, then sends the id in a new transaction and gets it. It fails without the fix.

https://issues.apache.org/jira/browse/ARTEMIS-6360

*/
@SuppressWarnings("unchecked")
private static Map<DuplicateIDCache, Set<ByteArray>> sentInTransaction(final Transaction tx) {
Map<DuplicateIDCache, Set<ByteArray>> sent = (Map<DuplicateIDCache, Set<ByteArray>>) tx.getProperty(TransactionPropertyIndexes.DUPLICATE_IDS);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like you could use tx.getOrCreateOperation:

AddOperation operation = tx.getOrCreateOperation(TransactionPropertyIndexes.ADD_MESSAGE, AddOperation::new);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is the answer to my question, right?

#6883

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, getOrCreateOperation fits better than a bare property. I'll rework it: a small TransactionOperation registered with tx.getOrCreateOperation(TransactionPropertyIndexes.DUPLICATE_IDS, ...) that holds the IDs the transaction has sent, by cache, and the check asks it. Adding to the cache stays where it is, in the AddDuplicateIDOperation that addToCache(id, tx, false) registers with tx.afterStore, so the timing doesn't change.

#6883 isn't the answer to this one, though. It covers a send outside a transaction, where addToCache(id, tx, true) put the ID in the cache at once. Inside a client transaction the ID only reaches the cache in afterCommit, so without this check a second send of it in the same transaction still passes cache.contains.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: the IDs now live in a TransactionOperation registered with tx.getOrCreateOperation(TransactionPropertyIndexes.DUPLICATE_IDS, ...), and the property-based helpers are gone. DuplicateDetectionTest passes locally; the CI run for the new commit is waiting for approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants