You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2026/07/17 12:54:00 UTC
[jira] [Resolved] (CAMEL-24046) camel-sql - JdbcCachedMessageIdRepository: failed insert permanently poisons the cache; cache is not thread-safe
[ https://issues.apache.org/jira/browse/CAMEL-24046?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claus Ibsen resolved CAMEL-24046.
---------------------------------
Resolution: Fixed
> camel-sql - JdbcCachedMessageIdRepository: failed insert permanently poisons the cache; cache is not thread-safe
> ----------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-24046
> URL: https://issues.apache.org/jira/browse/CAMEL-24046
> Project: Camel
> Issue Type: Bug
> Components: camel-sql
> Reporter: Federico Mariani
> Assignee: Federico Mariani
> Priority: Major
> Fix For: 4.18.4, 4.22.0
>
>
> Two related defects in JdbcCachedMessageIdRepository:
> 1. {{add(key)}} puts the key into the in-memory cache *before* calling {{super.add(key)}}. If the database insert fails (outage, PK race with another node) the exception propagates and the idempotent consumer never processes the message - but the key stays in the cache, so every redelivery is rejected as a duplicate. The message is never processed and never stored until the JVM restarts. Reproduced: after a failed insert, {{contains(key)}} returns true for a key that was never stored.
> 2. The cache is a plain {{HashMap}} mutated from concurrent consumer threads with no synchronization, and the {{cache}} field is non-volatile (a runtime {{reload()}} may never become visible to other threads). Concurrent puts during resize can lose entries (duplicate processing) or corrupt buckets. The hit/miss counters are unsynchronized ints.
> Fix: populate the cache only after the insert succeeds, use a ConcurrentHashMap with safe publication, and make the counters thread-safe.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)