This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch bt in repository https://gitbox.apache.org/repos/asf/camel.git
commit fc2d5f8028df47f900e4e92579805b8145949997 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Oct 17 08:49:26 2025 +0200 CAMEL-22566: backlog tracer - Drain queue before adding new trace event is more roboust --- .../apache/camel/impl/debugger/BacklogTracer.java | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/BacklogTracer.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/BacklogTracer.java index 1c6c82a047ba..011df4b71cf7 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/BacklogTracer.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/BacklogTracer.java @@ -135,15 +135,30 @@ public final class BacklogTracer extends ServiceSupport implements org.apache.ca return; } - // ensure there is space on the queue by polling until at least single slot is free - int drain = queue.size() - backlogSize + 1; - if (drain > 0) { - for (int i = 0; i < drain; i++) { - queue.poll(); + // pre-drain to make space + drain(false); + + boolean added = false; + while (!added) { + try { + added = queue.add(event); + } catch (IllegalStateException e) { + drain(true); } } + } - queue.add(event); + private void drain(boolean force) { + if (force) { + queue.poll(); + } else { + int drain = queue.size() - backlogSize + 1; + if (drain > 0) { + for (int i = 0; i < drain; i++) { + queue.poll(); + } + } + } } private boolean shouldTraceFilter(Exchange exchange) {
