Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.33k stars 1.97k forks source link

[QUERY] What happens when "partitionProcessor.processEvent" throws an exception? How can I stop processEvent retries when the client gets closed? #39986

Open 29877a96 opened 5 months ago

29877a96 commented 5 months ago

Query/Question I'm trying to follow the flow of an exception in partitionProcessor.processEvent, but the code comments and documentation are at best confusing or even contradict each other (JS calls out that the method is called, dotNet says it isn't, java docs don't mention much about this method). It's also unclear what happens after this method is invoked (recovery, partition lost, ...)

  1. Exception is raised here: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/PartitionPumpManager.java#L258
  2. Catched and wrapped in a PartitionProcessorException and rethrown in the try catch block: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/PartitionPumpManager.java#L268
  3. Wrapped exception is catched wrapped in a PartitionProcessorException (again) and rethrown by caller https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/PartitionPumpManager.java#L333
  4. Exception in the subscribe processEvents is handle in "handleError": https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/PartitionPumpManager.java#L220

Now the questions:

  1. Am I correct that processError is NOT invoked for "user code threw an exception in processEvent callback" (https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/eventhubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/PartitionPumpManager.java#L372C19-L372C72), given the if (!(throwable instanceof PartitionProcessorException)) { guard
  2. When an error is raised from processEvent, the partition processor will be closed with the CloseReason.LOST_PARTITION_OWNERSHIP (even though no doc mentions this as a root cause)? So another process picks up the processing from the last checkpoint, including this message? What is the impact of "shouldRethrow" on "user code exceptions". How is it different from the partition close that always happens on every error (partitionProcessor.close)? Throwing an error in the subscribe's errorConsumer has no effect, unless there is some onErrorDropped hook somewhere?
  3. If I want to retry specific errors like network issues indefinitely, I must do this in the processEvent callback without throwing? But if someone closes the client, how can I detect this and stop the infinite retry? What mechanisms are available within processEvent to detect a shutdown?

Why is this not a Bug or a feature Request? It's a question.

Setup (please complete the following information if applicable):

github-actions[bot] commented 5 months ago

@anuchandy @conniey @lmolkova

github-actions[bot] commented 5 months ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.