Repository navigation
Backlog
Labels
Description
What happens
A service on Obvs.ActiveMQ 7.0.2 that starts while its broker isn't accepting connections yet never receives any messages, even after the broker comes up. It logs one error for each source, then nothing:
fail: Obvs.Bus[0]
The Obvs bus reported an error: Error receiving Obvs.Types.ICommand from endpoint ServiceEndpoint[IServiceMessage1]
---> Apache.NMS.NMSConnectionException: Error connecting to amq:61616.
at Apache.NMS.ActiveMQ.ConnectionFactory.CreateConnection(String userName, String password)
at Obvs.ActiveMQ.Configuration.ConnectionFactoryExtensions.<>c__DisplayClass0_0.<CreateLazyConnection>b__0()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
...
at Obvs.ActiveMQ.MessageSource`1.<.ctor>b__7_1(IObserver`1 observer)
fail: Obvs.Bus[0]
The Obvs bus reported an error: Error receiving Obvs.Types.IRequest from endpoint ServiceEndpoint[IServiceMessage1]
...
info: Microsoft.Hosting.Lifetime[0]
Application started.
The host keeps running and looks healthy, but commands sent to it are never handled, and requests time out (No Response1 response to Request1 within 00:00:10). It doesn't recover until it's restarted.
How to reproduce
The examples showed this before #214 added a healthcheck: docker compose up started the service as soon as the ActiveMQ container started, before the broker was listening on 61616. Without Docker:
- Start
Examples/Service.ActiveMQwith no broker running. - Start a broker:
docker run -d -p 61616:61616 apache/activemq-classic:6.2.0. - Run
Examples/Clientand type a line. It's never received.
Likely cause
Not confirmed yet:
ConnectionFactoryExtensions.CreateLazyConnection(Obvs.ActiveMQ/Configuration/ConnectionFactoryExtensions.cs) wrapsCreateConnectionin aLazy<IConnection>withLazyThreadSafetyMode.ExecutionAndPublication. That mode caches an exception from the factory, so after a failed first connect, every later.Valuerethrows that exception without trying to connect again.- The bus does resubscribe to a source that errors (
CatchAndHandleinObvs/Extensions/ObservableExtensions.cs, throughEndpointExtensions). ButMessageSourcereads_lazyConnection.Valueon each subscribe, so a resubscription can't get past the cached exception. - Only one error was logged for each source, not one for each retry. So it's worth checking what the resubscription does there too.
- The publishers share the same lazy connection, so a client started before its broker probably can't send either. I haven't checked this.
What would fix it
- Don't cache a failed connect. For example, use
LazyThreadSafetyMode.PublicationOnly, or a connection holder that tries again after a failure. - Retry with a delay, so a broker that's down doesn't turn into a tight loop of resubscriptions. The JetStream source does this (PR Obvs.NATS JetStream: keep receiving through lost connections #141), and the same note there about
Publish().RefCount()holding a terminated subject applies to ActiveMQ's topic sources, which usePublishRefCountRetriable. - Add a broker test: start the bus with the broker down, start the broker, and assert a command is received.
Whether failover: broker URIs avoid this hasn't been checked either.
🤖 Generated with Claude Code
Activity