shashank created CAMEL-27478:
--------------------------------

             Summary: camel-ftp - the health checks of two producers to the 
same host have the same id: stopping one removes the check of the other, and 
the checks then connect the stopped producer
                 Key: CAMEL-27478
                 URL: https://issues.apache.org/jira/browse/CAMEL-27478
             Project: Camel
          Issue Type: Bug
          Components: camel-ftp
            Reporter: shashank
            Assignee: shashank


h3. What happens

Producer health checks are off by default; they are turned on with 
{{camel.health.producersEnabled=true}}.

The id of the health check of an ftp, ftps or sftp producer is 
{{"producer:ftp-" + host}} ({{RemoteFileProducerHealthCheck}}), and 
{{AbstractHealthCheck.equals}} compares the id only. Two producers to the same 
host get the same id: two routes that write into different directories of one 
server, the producers of a {{toD}}, or the instances of one endpoint (the 
producer is not a singleton, so a route with concurrent exchanges can have 
several). The registry keeps only the first check of an id when it calls the 
checks, so only one producer is checked. When one producer stops, 
{{removeHealthCheck}} removes the first equal check, which can belong to a 
producer that is still running. The check left behind belongs to the stopped 
producer: each readiness call then runs {{doPreWriteCheck}} on it, which 
connects it again. Nothing closes that connection (its stop already ran), and 
the probe opens it again whenever the server drops it, while the running 
producer is no longer checked.

h3. How to reproduce

Routes a and b that write to {{ftp://user@host/a}} and {{ftp://user@host/b}} of 
the embedded FTP server of the camel-ftp tests, with producer health checks 
enabled. Send to b, then to a, and stop route a: the check left is the one of 
the stopped producer of a, and the next readiness call opens a new FTP session 
for it (2 sessions on the server instead of 1).

Found with a TLA+ model of the producers health-check repository.

h3. Fix

The id also names the endpoint, as the AWS producer checks do with the endpoint 
id: {{producer:ftp-<host>-<endpoint id>}}, plus {{-2}}, {{-3}}, ... for the 
other producers of an endpoint that has more than one at a time. A producer 
takes the lowest number that no started producer of its endpoint uses, and 
gives it back when it stops, so the id of a single producer stays the same when 
its route is stopped and started (an endpoint created again, as after a reload, 
has a new endpoint id). The id still has no user name or password (CAMEL-24717 
shows why the endpoint URI is not used). A configuration that names the old id 
should use a pattern such as {{producer:ftp-myhost-*}}. Readiness now checks 
each started producer (one {{NOOP}} each), where it checked one per host before.

Not changed: a probe already running when the producer stops can still connect 
it once (narrow window). The producer check waits for an upload in progress, 
which is another ticket.

_Filed with Claude Code on behalf of allthingssecurity._



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

Reply via email to