Error handling CatchUpSubscription - JVM Client 3.0.0

Hi, I’m in the process of getting familiar with the jvm-client db-client-java:3.0.0. Got a question regarding the error handling in a CatchUpSubscription. Given this code snippet:

client.subscribeToStream(
	streamName,
	new SubscriptionListener {
	  override def onEvent(subscription: Subscription, event: ResolvedEvent): Unit = {
		throw new Exception("just for testing")
	  }

	  override def onError(subscription: Subscription, throwable: Throwable): Unit = {
		println(throwable.getMessage)
	  }

	  override def onCancelled(subscription: Subscription): Unit = {
		println("subscription cancelled")
	  }
	},
	SubscribeToStreamOptions.get()
	  .fromStart()
	  .resolveLinkTos()
)

I see that when the subscription receives an event and the onError is called, and throws an Exception - the next step I would assume to happen is that onError would be called. But this is not the case. Instead it only calls the onCancelled. What is actually the expected behaviour here?

Hi Kristoffer,

We’re using C#, so I’m not completely sure, but perhaps the onCancelled, actually means the subscription has been dropped for some reason Catch-up subscriptions | EventStoreDB Documentation.

Cheers,

Peter

I am also not familiar with the Java client, in C# we only have OnDropped with a status. I guess that onError is called when there’s a connection issue. However, when there’s an error in the catchup subscription event handler, the subscription drops. It’s because we don’t really know what to do in this case. Normally, you need to handle things like retries in your handler, so it doesn’t throw. If it actually throws, we assume that something unexpected happened, and the subscription cannot continue.

The normal course of action here is to make the service unhealthy and kill/restart it. If you get it in a restart loop, you should be alerted by your APM.