Claus Ibsen created CAMEL-26945:
-----------------------------------

             Summary: camel-core - the time an inflight exchange has been at 
its node is garbage: MessageHistory.getElapsedSinceCreated() subtracts wall 
clock millis from System.nanoTime()
                 Key: CAMEL-26945
                 URL: https://issues.apache.org/jira/browse/CAMEL-26945
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found on 2026-11-13 while adding the oldest inflight exchange to camel status 
(CAMEL-26941), with the 4.24.0-SNAPSHOT camel-launcher on macOS, JDK 25. On 
main.

The time an inflight exchange has been at its current node is garbage while the 
exchange is still at that node. A dev mode integration with a route that waits 
30 seconds ({{delay}}) has this in the inflight section of its status 
({{~/.camel/<pid>-status.json}}, as {{camel get inflight}} and the TUI show 
it), on a machine that has been up 16 days:

{code}
{"exchangeId":"...-0000000000000001","fromRouteId":"slow","atRouteId":"slow","nodeId":"delay1","nodeSource":"app.camel.yaml:15","elapsed":1417238100396303,"duration":3632}
{code}

1417238100396303 is about the uptime of the machine in nanoseconds (16.4 days).

Cause (read in the code): 
{{DefaultInflightRepository.InflightExchangeEntry.getElapsed()}} takes the last 
message history entry, and while that node is still in progress ({{getElapsed() 
== 0}}) it calls {{MessageHistory.getElapsedSinceCreated()}}. The default 
method in camel-api is {{return System.nanoTime() - getTime();}}, and 
{{getTime()}} is {{MonotonicClock.getCreated()}}, which is the wall clock in 
millis ({{TimeSource.currentTimeMillis()}}): nanos since an arbitrary origin 
minus epoch millis.

The descriptions of the two fields in {{InflightConsole}} are also swapped: 
{{elapsed}} says "Elapsed time in milliseconds since the exchange started", but 
it is the time at the current node; {{duration}} says "Duration in milliseconds 
the exchange has been at the current node", but it is 
{{exchange.getClock().elapsed()}}, the time since the exchange was created 
(which is right: 3632 above).

Fix idea: measure on the monotonic clock of the entry, in millis 
({{DefaultMessageHistory}} has a {{MonotonicClock}} whose {{elapsed()}} is 
that), and swap the two descriptions (and regenerate what is generated from 
them).

_Claude Code on behalf of Claus Ibsen_



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

Reply via email to