You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Federico Mariani (Jira)" <ji...@apache.org> on 2026/07/13 09:36:00 UTC

[jira] [Created] (CAMEL-24046) camel-sql - JdbcCachedMessageIdRepository: failed insert permanently poisons the cache; cache is not thread-safe

Federico Mariani created CAMEL-24046:
----------------------------------------

             Summary: 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


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)