shashank created CAMEL-26705:
--------------------------------
Summary: camel-sql - JdbcOrphanLockAwareIdempotentRepository and
JdbcCachedMessageIdRepository are not restart safe
Key: CAMEL-26705
URL: https://issues.apache.org/jira/browse/CAMEL-26705
Project: Camel
Issue Type: Bug
Components: camel-sql
Reporter: shashank
Assignee: shashank
A stopped service runs {{doInit()}} again when it is started
({{BaseService.init()}}: "allow to initialize again if stopped or failed").
This happens to the idempotent repository when it is stopped and started, when
its route is removed and added again (route reload, JMX), or when the
CamelContext is restarted. {{JdbcOrphanLockAwareIdempotentRepository.doInit()}}
is not safe to run twice:
* It rewrites its own field: {{updateTimestampQuery =
updateTimestampQuery.replaceFirst(DEFAULT_TABLENAME, getTableName())}}. With a
table name that contains the default name, such as
{{CAMEL_MESSAGEPROCESSED_ORDERS}} or {{MYSCHEMA.CAMEL_MESSAGEPROCESSED}} (the
case of CAMEL-20010), every restart adds the suffix again: {{UPDATE
CAMEL_MESSAGEPROCESSED_ORDERS_ORDERS ...}}. The keep-alive then fails on every
run, which is only logged at ERROR, so the leases of the node are no longer
refreshed and another node takes over keys it is still processing after
{{lockMaxAgeMillis}}. Taking over an orphan lock in {{insert}} uses the same
statement and fails with an SQL error.
* It creates and schedules the keep-alive executor, which is shut down only in
{{doShutdown()}}. Every stop/start leaves the previous executor running, and a
stopped repository keeps refreshing its leases.
{{JdbcCachedMessageIdRepository.doInit()}} rewrites its {{queryAllString}} the
same way; there the second start fails, because reloading the cache runs the
broken query.
CAMEL-20010 fixed the first point for the statements of the parent
{{JdbcMessageIdRepository}} by deriving them from {{DEFAULT_*}} constants;
{{updateTimestampQuery}} and {{queryAllString}} were not covered.
Expected: after any number of stop/start cycles the repositories use the same
SQL, and the orphan-lock repository runs one keep-alive task, and none while it
is stopped.
Suggested fix: derive {{updateTimestampQuery}} and {{queryAllString}} from
default constants in {{doInit()}} as the parent class does, and create the
keep-alive executor in {{doStart()}} and shut it down in {{doStop()}}.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)