[ 
https://issues.apache.org/jira/browse/CAMEL-27435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Work on CAMEL-27435 started by shashank.
----------------------------------------
> camel-sjms - connection recovery can leave the consumer without JMS 
> consumers, leak a connection after stop, and stop working after an Error
> --------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-27435
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27435
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-sjms
>            Reporter: shashank
>            Assignee: shashank
>            Priority: Major
>
> h3. What happens
> Four problems of the connection recovery of the sjms consumer 
> ({{SimpleMessageListenerContainer}}), at the edges of its lifecycle. They 
> follow CAMEL-25312, CAMEL-25612 and CAMEL-25659.
> *1. A recovery can end with a started connection and no JMS consumer, and 
> report success.* {{refreshConnectionAndCountFailures}} closes the old 
> connection, which also closes its sessions and consumers, but leaves the 
> {{sessions}}/{{consumers}} fields set. {{initConsumers}} creates nothing when 
> {{consumers}} is set, and the success check only asks whether {{consumers}} 
> is null or a new failure was counted. So a recovery that starts while 
> {{consumers}} still holds the consumers of the connection it closes ends with 
> a new started connection without consumers and reports success. Nothing 
> starts another recovery: the route stays started and stops consuming until it 
> is restarted. It happens when the connection fails between 
> {{createConnection}} and {{initConsumers}} of {{doStart}}, or when a failure 
> report of the old connection arrives after the consumer was stopped and the 
> same consumer instance is started again (as JMX does).
> *2. A failure report after the stop starts a recovery that opens a connection 
> and consumers nothing closes.* {{scheduleConnectionRecovery}} does not look 
> at the state of the container, and {{doStop}} sets the recovery pool and task 
> to null, so a late {{onException}} creates a new pool and schedules a 
> recovery. After {{doShutdown}} that recovery creates a connection and its 
> consumers that stay open. Right after a stop, two recoveries can be in flight 
> (the attempt of the old pool, which {{shutdown()}} does not wait for, and the 
> new one).
> *3. {{doShutdown}} reads and clears {{connection}} without 
> {{connectionLock}}.* A recovery that replaces the connection between the 
> close and the null leaves the new connection, with its consumers, open and 
> unreferenced.
> *4. An {{Error}} in a recovery attempt disables the recovery for good.* 
> {{recoverConnection}} catches {{Exception}} only. An {{Error}} (for example a 
> {{NoClassDefFoundError}} of the client while it creates a session or consumer 
> on the new connection) ends the schedule of the {{BackgroundTask}}, which 
> still answers {{isRunning()}}, so no later connection failure is ever 
> recovered: the new connection stays open without consumers, and when it 
> fails, nothing recovers it.
> h3. How to reproduce
> With the embedded broker of the module's tests and a connection factory that 
> counts connections and consumers: (1) let the connection call its exception 
> listener as soon as it is set: after the recovery a message is not received, 
> the new connection has 0 consumers; (1, 2) stop the consumer, call 
> {{onException}} on the container, start the same consumer: the next message 
> is not received; (2) stop the route, then call {{onException}}: a second 
> connection with 2 consumers stays open; (3) hold the close of the connection 
> in {{doShutdown}} and report a failure: a connection stays open after the 
> stop; (4) let the first {{createSession}} of the recovery's connection throw 
> a {{NoClassDefFoundError}}, then report a failure of that connection: no new 
> connection is created and the next message is not received.
> Found with a TLA+ model of the recovery (late and repeated failure reports, 
> recovery attempts in old and new pools, stop, shutdown, restart, suspend, 
> broker restarts, throws, an Error of the client).
> h3. Fix
> Clear the consumers and sessions when the refresh closes the old connection; 
> a {{recoveryAllowed}} flag under {{connectionLock}} (from {{doStart}} until 
> {{doStop}}) so that {{onException}} and {{scheduleConnectionRecovery}} do 
> nothing after the stop; a recovery attempt goes on only while it is the 
> container's {{recoverTask}}; {{doShutdown}} closes and clears the connection 
> under {{connectionLock}}; an {{Error}} in an attempt cancels its task and 
> clears {{recoverTask}} before it is rethrown. (An {{Error}} from creating the 
> connection itself leaves no connection that could fail later; the route needs 
> a restart then, as before.)
> _Filed with Claude Code on behalf of allthingssecurity._



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to