Aurélien Pupier created CAMEL-27776:
---------------------------------------
Summary: camel-seda - a message sent before its consumer starts is
lost when the producer that sent it is stopped, as the queue reference is
released with the messages
Key: CAMEL-27776
URL: https://issues.apache.org/jira/browse/CAMEL-27776
Project: Camel
Issue Type: Bug
Components: camel-seda
Affects Versions: 4.24.0
Reporter: Aurélien Pupier
h3. Problem
A message that is sent to a {{seda:}} queue before the consumer of the queue is
started is lost, when the producer that sent it is stopped before the consumer
starts.
When the last producer of a SEDA endpoint stops and no consumer is registered,
{{SedaComponent.onShutdownEndpoint()}} releases the shared {{QueueReference}},
even if the queue still holds messages. The consumer that starts later does not
find the queue again, and {{SedaEndpoint.registerQueueIfStale()}} creates a
new, empty one: the messages of the released queue are never consumed.
h3. Reproducer
{code:java}
from("seda:bar").routeId("consumer").autoStartup(false).to("mock:result");
...
try (ProducerTemplate producer = context.createProducerTemplate()) {
producer.sendBody("seda:bar", "hello");
}
// the producer is stopped now, and it was the only user of the queue
context.getRouteController().startRoute("consumer");
// "hello" is never received by mock:result
{code}
It fails every time, with no load and no other component. The same happens when
the route that sends the message is stopped before the consumer route is
started.
h3. Impact
It was found as the cause of the flaky test CAMEL-27547
(MasterRoutePolicyRouteLifecycleTest): a route policy starts the consumer of a
route {{autoStartup=false}} after it was elected master, and the test sent its
message in the meantime (about 1 run in 3 failed on a machine with all the CPUs
busy, and 4% on CI).
h3. Proposed fix
Keep the {{QueueReference}} in {{SedaComponent.onShutdownEndpoint()}} while the
queue still holds messages, so the consumer that starts later finds the same
queue. The reference is removed when the component stops, as before.
h3. Behavior change
A queue that still holds messages stays registered in the component after its
last endpoint is released (before, the queue was dropped with its messages). It
is cleared when the component stops, or reused when an endpoint of the same
queue starts again. This must be noted in the upgrade guide.
----
_Created by IBM Bob (AI) on behalf of Aurélien Pupier (apupier)._
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)