Claus Ibsen created CAMEL-24678:
-----------------------------------
Summary: camel-jbang: infra ps shows only one instance per service
alias and picks its PID non-deterministically
Key: CAMEL-24678
URL: https://issues.apache.org/jira/browse/CAMEL-24678
Project: Camel
Issue Type: Bug
Components: camel-jbang
Reporter: Claus Ibsen
{{camel infra ps}} renders a PID column, but it can only ever show one instance
per service alias. When the same service is started twice, the second instance
is invisible and the PID shown for the first is picked non-deterministically.
h3. Cause
{{InfraBaseCommand.listServices()}} builds its rows from a {{Map<String,
InfraServiceAlias>}} keyed by *alias*, so there is exactly one {{Row}} per
alias. The PID for that row comes from {{findPid(alias)}}, which returns the
first {{~/.camel/infra-<alias>-<pid>.json}} file that {{File.list()}} happens
to return:
{code:java}
private String findPid(String key) {
for (String s : Objects.requireNonNull(p.toFile().list())) {
if (s.startsWith("infra-" + key + "-") && s.endsWith(".json")) {
return pidFromPidFile(s);
}
}
return null;
}
{code}
{{File.list()}} order is filesystem-dependent, so with two {{infra-ftp-*.json}}
files present it is not defined which PID is reported. {{getServiceData(alias,
pid)}} then renders the service data of that same arbitrary instance, so the
connection details shown can belong to a different process than the user
expects.
{{infra stop <alias>}} is not affected -- it goes through {{findPids(name)}}
and stops every matching instance.
h3. Impact
* A second instance of an already-running service cannot be seen in {{infra
ps}} at all.
* The PID and SERVICE_DATA columns may describe a stale instance, which is
misleading when connecting to the service.
* Anything that keys off the reported PID is unreliable. This surfaced
concretely in {{InfrastructureITCase}}: a leaked ftp instance made {{infra ps}}
keep reporting the old PID, so assertions on the newly started PID could never
match (fixed on the test side in commit f2cc9f8767b3, but the underlying
{{infra ps}} behaviour remains).
h3. Suggested fix
Emit one row per running instance rather than one row per alias, so duplicate
aliases each get their own PID and SERVICE_DATA. {{infra list}} (which has no
PID column and describes the catalog rather than running processes) should keep
its current one-row-per-alias shape.
----
_Reported by Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)