James Netherton created CAMEL-27777:
---------------------------------------
Summary: camel-core: BacklogTracer message history stops updating
when exchanges from multiple routes interleave
Key: CAMEL-27777
URL: https://issues.apache.org/jira/browse/CAMEL-27777
Project: Camel
Issue Type: Bug
Components: came-core
Reporter: James Netherton
Assignee: James Netherton
Fix For: 4.25.0
The latest message history captured by {{BacklogTracer}} (exposed via
{{getLatestMessageHistory()}} and the {{message-history}} dev console) can stop
updating permanently once exchanges from different routes interleave. It then
keeps returning the same old exchange.
h3. Steps to reproduce
Run Camel with the backlog tracer on standby and message history enabled
({{camel.trace.standby=true}}, {{camel.main.messageHistory=true}}, both set by
the dev profile), with two routes that run concurrently:
{code:java}
from("timer:a?period=200").routeId("a").setBody(constant("a")).log("a");
from("timer:b?period=200").routeId("b").setBody(constant("b")).log("b");
{code}
Poll the {{message-history}} dev console (or
{{BacklogTracer.getLatestMessageHistory()}}) every 500 ms.
h3. Expected
The history keeps moving to newer completed exchanges.
h3. Actual
The history updates for a few seconds, then returns the same exchange id and
timestamp on every poll from then on. In one run it froze after about 5 seconds
and was still frozen 5.5 seconds later, when polling stopped. Before freezing,
some histories were also missing the start of the exchange (first entry has
{{first=false}}).
h3. Analysis
In {{BacklogTracer.traceEvent}}, the first event that reaches an empty
{{provisionalHistoryQueue}} claims the queue for its exchange, whatever kind of
event it is:
{code:java}
var head = provisionalHistoryQueue.peek();
...
match = tid == null || tid.equals(event.getExchangeId()) ||
tid.equals(event.getCorrelationExchangeId());
...
if (match || appendMode) {
boolean added = provisionalHistoryQueue.offer(event);
boolean original = head != null && event.getRouteId() != null &&
event.getRouteId().equals(head.getRouteId());
if (event.isLast() && original) {
// move provisional history to completeHistoryQueue and clear
provisional
{code}
When the queue has just been cleared and the next event to arrive is the
{{last}} event of an exchange already in flight (from a concurrently running
route):
* {{head}} is null, so {{original}} is false and the exchange is never
completed.
* That event becomes the head, but its exchange has finished, so no further
event matches it.
* Events from every other exchange fail the {{match}} check and are discarded,
so {{completeHistoryQueue}} is never replaced again.
When the claiming event is a middle event instead, the exchange does complete,
but its history is missing the steps before that event.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)