azure-sdk-for-java: [BUG] Spurious stack traces in log when EventHubProducerClient encounters onSessionRemoteClose

Describe the bug We have a service to sends messages to the eventhub using the com.azure:azure-messaging-eventhubs:5.18.6 artifact, with very low volume (less than 200 msg/day).

Recently (since Aug. 17) we started seeing regular exceptions in our logs which indicates a bug in the library that leads to dropped messages.

Exception or Stack Trace We se a batch of 4 log.errors and 1 log.warn from the library. First we get a log.error by reactor.core.publisher.Operators:

reactor.core.Exceptions$ErrorCallbackNotImplemented: com.azure.core.amqp.exception.AmqpException: onSessionRemoteClose connectionId[MF_a5ecd4_1724187994893], entityName[cbs-session] condition[Error{condition=amqp:connection:forced, description='The connection was closed by container '69f22c69b0244cbe8b723d4b44f2efe7_G26' because it did not have any active links in the past 300000 milliseconds. TrackingId:69f22c69b0244cbe8b723d4b44f2efe7_G26, SystemTracker:gateway5, Timestamp:2024-08-20T22:42:17', info=null}], errorContext[NAMESPACE: evh-bibis-prod-001.servicebus.windows.net. ERROR CONTEXT: N/A, PATH: cbs-session]
Caused by: com.azure.core.amqp.exception.AmqpException: onSessionRemoteClose connectionId[MF_a5ecd4_1724187994893], entityName[cbs-session] condition[Error{condition=amqp:connection:forced, description='The connection was closed by container '69f22c69b0244cbe8b723d4b44f2efe7_G26' because it did not have any active links in the past 300000 milliseconds. TrackingId:69f22c69b0244cbe8b723d4b44f2efe7_G26, SystemTracker:gateway5, Timestamp:2024-08-20T22:42:17', info=null}], errorContext[NAMESPACE: evh-bibis-prod-001.servicebus.windows.net. ERROR CONTEXT: N/A, PATH: cbs-session]
	at com.azure.core.amqp.implementation.ExceptionUtil.toException(ExceptionUtil.java:90)
	at com.azure.core.amqp.implementation.handler.SessionHandler.onSessionRemoteClose(SessionHandler.java:139)
	at org.apache.qpid.proton.engine.BaseHandler.handle(BaseHandler.java:152)
	at org.apache.qpid.proton.engine.impl.EventImpl.dispatch(EventImpl.java:108)
	at org.apache.qpid.proton.reactor.impl.ReactorImpl.dispatch(ReactorImpl.java:324)
	at org.apache.qpid.proton.reactor.impl.ReactorImpl.process(ReactorImpl.java:291)
	at com.azure.core.amqp.implementation.ReactorExecutor.run(ReactorExecutor.java:91)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

Then we get a log.warn from com.azure.core.amqp.implementation.RequestResponseChannel

The connection was closed by container '34a13da5722a4a3eae91914bf10d8530_G16' because it did not have any active links in the past 300000 milliseconds. TrackingId:34a13da5722a4a3eae91914bf10d8530_G16, SystemTracker:gateway5, Timestamp:2024-08-21T08:27:26, errorContext[NAMESPACE: evh-bibis-prod-001.servicebus.windows.net. ERROR CONTEXT: N/A, PATH: $cbs, REFERENCE_ID: cbs:sender, LINK_CREDIT: 98]

Then another log.error from reactor.core.publisher.Operators with message Operator called default onErrorDropped and stacktrace:

reactor.core.Exceptions$ErrorCallbackNotImplemented: com.azure.core.amqp.exception.AmqpException: onSessionRemoteClose connectionId[MF_029ac1_1724193737281], entityName[cbs-session] condition[Error{condition=amqp:connection:forced, description='The connection was closed by container '34a13da5722a4a3eae91914bf10d8530_G16' because it did not have any active links in the past 300000 milliseconds. TrackingId:34a13da5722a4a3eae91914bf10d8530_G16, SystemTracker:gateway5, Timestamp:2024-08-21T08:27:26', info=null}], errorContext[NAMESPACE: evh-bibis-prod-001.servicebus.windows.net. ERROR CONTEXT: N/A, PATH: cbs-session]
Caused by: com.azure.core.amqp.exception.AmqpException: onSessionRemoteClose connectionId[MF_029ac1_1724193737281], entityName[cbs-session] condition[Error{condition=amqp:connection:forced, description='The connection was closed by container '34a13da5722a4a3eae91914bf10d8530_G16' because it did not have any active links in the past 300000 milliseconds. TrackingId:34a13da5722a4a3eae91914bf10d8530_G16, SystemTracker:gateway5, Timestamp:2024-08-21T08:27:26', info=null}], errorContext[NAMESPACE: evh-bibis-prod-001.servicebus.windows.net. ERROR CONTEXT: N/A, PATH: cbs-session]
	at com.azure.core.amqp.implementation.ExceptionUtil.toException(ExceptionUtil.java:90)
	at com.azure.core.amqp.implementation.handler.SessionHandler.onSessionRemoteClose(SessionHandler.java:139)
	at org.apache.qpid.proton.engine.BaseHandler.handle(BaseHandler.java:152)
	at org.apache.qpid.proton.engine.impl.EventImpl.dispatch(EventImpl.java:108)
	at org.apache.qpid.proton.reactor.impl.ReactorImpl.dispatch(ReactorImpl.java:324)
	at org.apache.qpid.proton.reactor.impl.ReactorImpl.process(ReactorImpl.java:291)
	at com.azure.core.amqp.implementation.ReactorExecutor.run(ReactorExecutor.java:91)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

Then another log.error from com.azure.core.amqp.implementation.AmqpChannelProcessor with the exception message:

Cannot invoke "java.util.List.add(Object)" because "this._sessions" is null

And finally an internal NPE, logged by reactor.core.publisher.Operators (which I suspect leads to the dropped message):

reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.NullPointerException: Cannot invoke "java.util.List.add(Object)" because "this._sessions" is null
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.List.add(Object)" because "this._sessions" is null
	at org.apache.qpid.proton.engine.impl.ConnectionImpl.session(ConnectionImpl.java:91)
	at org.apache.qpid.proton.engine.impl.ConnectionImpl.session(ConnectionImpl.java:39)
	at com.azure.core.amqp.implementation.ReactorConnection.lambda$createSession$15(ReactorConnection.java:311)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(Unknown Source)
	at com.azure.core.amqp.implementation.ReactorConnection.lambda$createSession$16(ReactorConnection.java:308)
	at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113)
	at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.onNext(MonoPeekTerminal.java:180)
	at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onNext(FluxHide.java:137)
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.request(MonoIgnoreThen.java:164)
	at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.request(FluxHide.java:152)
	at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.request(MonoPeekTerminal.java:139)
	at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:171)
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.request(MonoFlatMap.java:194)
	at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:171)
	at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:171)
	at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.request(FluxPeekFuseable.java:144)
	at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.request(Operators.java:2331)
	at com.azure.core.amqp.implementation.AmqpChannelProcessor.requestUpstream(AmqpChannelProcessor.java:336)
	at com.azure.core.amqp.implementation.AmqpChannelProcessor.lambda$onError$4(AmqpChannelProcessor.java:230)
	at reactor.core.publisher.LambdaMonoSubscriber.onNext(LambdaMonoSubscriber.java:171)
	at reactor.core.publisher.MonoDelay$MonoDelayRunnable.propagateDelay(MonoDelay.java:270)
	at reactor.core.publisher.MonoDelay$MonoDelayRunnable.run(MonoDelay.java:285)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

To Reproduce I do not have steps to reproduce, but I can see we are not the only one seeing the issue (looks related to #41535 ~and perhaps 41489~), But I do suspect a simple app that sends test messages at a very low frequency will trigger the issue.

Code Snippet We instantiate our client very simple:

@Bean
public EventHubProducerClient eventHubProducerClient() {
     return new EventHubClientBuilder()
            .connectionString(properties.connectionString())
            .shareConnection()
            .buildProducerClient();
}

And the sending code is like:

public void sendEvent(String eventBody) {
    eventHubProducerClient.send(List.of(new EventData(eventBody)));
}

Expected behavior If the server disconnects the client due to inactivity, the client should notice and reconnect at next send attempt.

Setup (please complete the following information):

  • Library/Libraries: com.azure:azure-messaging-eventhubs:5.18.6 / com.azure:azure-identity:1.13.2
  • Java version: 21
  • App Server/Environment: Tomcat in spring boot running in a docker container
  • Frameworks: Spring Boot

Additional information I suspect an infrastructure applied change around August 17. that perhaps lowered the timeout on the server side has lead to this surfacing.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 48 (24 by maintainers)

Most upvoted comments

Thanks for linking @hylander0. Hi @padmapriyanalam, @pje477, thanks for reaching out. I will update https://github.com/Azure/azure-sdk-for-java/issues/41736 that Justin referenced once the Service Bus (with new cache addressing NPE) is shipped. Let’s use this issue for tracking Event Hubs.

Hi @djarnis73, thanks for the detailed log and cleaning up it, it was very useful!

I did the RCA - The Connection supports various communication pipes: channel, send link, and receive link. One specific channel, CBS, handles authentication and can face transient disconnects. We use an AmqpChannelProcessor (ACP) to automatically recreate the CBS channel if it disconnects, provided the parent Connection is healthy. If the parent Connection disconnects, the ACP is shut down to prevent it from creating new CBS channels. The issue was that when the connection disconnected, the connection initiated the ACP shutdown, but a Thread in the ACP attempted to recreate the channel before the shutdown process was fully completed. Attempt to use a disconnected connection caused the NPE. Depending on the timing, this issue may or may not occur, for instance, if the Thread in the ACP receives the shutdown signal (from connection Thread) before it retries channel creation.

We’re introducing a new type called RequestResponseChannelCache to replace AmqpChannelProcessor, avoiding channel creation on disposed connections. These changes have already merged and will be included in the September release happening soon. In the Event Hubs September version, the RequestResponseChannelCache will be automatically selected when the V2 stack is opted in.

I’ll update the thread once the new version is out so you can validate it in the test environment. thank you!

I think trying out the V2 beta would be an option for us. Where can I find the details on how to test it?

The beta is available as: azure-messaging-eventhubs 5.19.0-beta.2. Setting the environment variable com.azure.messaging.eventhubs.v2=true when running your application will use the v2 stack.

new EventHubClientBuilder()
        .connectionString(properties.connectionString())
        .configuration(new com.azure.core.util.ConfigurationBuilder()
                .putProperty("com.azure.messaging.eventhubs.v2", "true")
                .build())
        .buildProducerClient();

Hello @clevelandcs, @djarnis73, beta.3 is now moved to GA. Please use version 5.19.0

<dependency>
  <groupId>com.azure</groupId>
  <artifactId>azure-messaging-eventhubs</artifactId>
  <version>5.19.0</version>
</dependency>

You will also need to opt-in for the v2 stack with GA i.e., the earlier suggestion about providing configuration for selecting v2 remains applicable.

new EventHubClientBuilder()
        .connectionString(properties.connectionString())
        .configuration(new com.azure.core.util.ConfigurationBuilder()
                .putProperty("com.azure.messaging.eventhubs.v2", "true")
                .build())
        .buildProducerClient();

The GA azure-messaging-eventhubs:5.19.0 should use azure-core-amqp: 2.9.9 and azure-core: 1.52.0. Run mvn dependency:tree to check for any dependency conflicts.

Since the fix has been confirmed in the beta, I’ll proceed to close this issue. Thank you both for your assistance with testing the betas.

@djarnis73, that’s great news, thank you for the help with running the beta.3 and confirming that NullPointerException no longer happens.

Reg log: the library will log all (transient or non-transient) disconnect events, session-close is one such event and logged for debugging purposes in the case of an incident.

We’ll close this issue with maven coordinates once the GA release is complete. We’re waiting for stress-run sign-off since the overall change is big.

Hello @yeah007, assuming no unexpected issues, the updated Event Hubs library with the fix should be available before September 26th.

Ok, so I managed to deploy V2 on our test environment on Friday, so it has now been running over the weekend, what I have observed so far is:

  • ReactorConnectionCache is logging (I see messages like: Waiting to connect and active. / Emitting the new active connection. / closing connection (Terminating the connection recovery support.). / closing connection (Terminating the connection recovery support.).)
  • I still see the NPE (has happened 5 times since friday), will post full stack trace below.
java.lang.NullPointerException: Cannot invoke "java.util.List.add(Object)" because "this._sessions" is null
	at org.apache.qpid.proton.engine.impl.ConnectionImpl.session(ConnectionImpl.java:91)
	at org.apache.qpid.proton.engine.impl.ConnectionImpl.session(ConnectionImpl.java:39)
	at com.azure.core.amqp.implementation.ReactorConnection.lambda$createSession$15(ReactorConnection.java:311)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(Unknown Source)
	at com.azure.core.amqp.implementation.ReactorConnection.lambda$createSession$16(ReactorConnection.java:308)
	at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:113)
	at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.onNext(MonoPeekTerminal.java:180)
	at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.onNext(FluxHide.java:137)
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.request(MonoIgnoreThen.java:164)
	at reactor.core.publisher.FluxHide$SuppressFuseableSubscriber.request(FluxHide.java:152)
	at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.request(MonoPeekTerminal.java:139)
	at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:171)
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.request(MonoFlatMap.java:194)
	at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:171)
	at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:171)
	at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.request(FluxPeekFuseable.java:144)
	at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.request(Operators.java:2331)
	at com.azure.core.amqp.implementation.AmqpChannelProcessor.requestUpstream(AmqpChannelProcessor.java:336)
	at com.azure.core.amqp.implementation.AmqpChannelProcessor.lambda$onError$4(AmqpChannelProcessor.java:230)
	at reactor.core.publisher.LambdaMonoSubscriber.onNext(LambdaMonoSubscriber.java:171)
	at reactor.core.publisher.MonoDelay$MonoDelayRunnable.propagateDelay(MonoDelay.java:270)
	at reactor.core.publisher.MonoDelay$MonoDelayRunnable.run(MonoDelay.java:285)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
	at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

Let me know what else I can provide (I just now managed to enable full debug logging, so I can probably provide some of those tomorrow).

Hi @djarnis73 - regarding logging, a reference log4j2.xml and logback.xml can be found here with DEBUG logging enabled.

To verify V2 stack is enabled, we can check if there are logs with class name “com.azure.core.amqp.implementation.ReactorConnectionCache”, which should be present at the start of the logs when a connection is established.

To give an additional context, even with v2, we will still see the disconnect events - “onSessionRemoteClose”, “the connection was closed by container…”. The broker will disconnect if there is no activity, and the next send attempt by the application should force library to reconnect.

Can we check

  1. If V2 is enabled by inspecting if there are logs from “ReactorConnectionCache” class in logs,
  2. If we still see this error with V2 - “Error: java.lang.NullPointerException: Cannot invoke ava.util.List.add(Object) because this._sessions is null”,
  3. If next send attempt reconnects and send events though there were session/connection close/disconnects.

Sure, go ahead. I’m not too deep into our application or the services it uses I just happened to be the one investigating the issues or log monitoring found. So a lot of guesswork on my side.

To clarify, the cause of Service Bus issue 41489 is unrelated though both log shows link disconnects; Service Bus 41489 was a thread bottleneck problem.

The Service Bus has been running on the V2 stack engine for several months and is generally available. Event Hub is currently being integrated into the V2 stack engine and is in the testing and feature parity phase, with a beta release in progress. From our local testing, EH with V2 stack engine do not face this issue observed in lower traffic environment.

Between @djarnis73, I’ll clean up your comment in 41489 to prevent any confusion for others running into issue similar to that Service Bus case or this Event Hub issue. Hope that’s alright with you.