Skip to content

Commit 0e52fd7

Browse files
Minor changes to lease scanner (#428)
* Add logging if the scanner threw an exception. * Change logging level to warn when scanner shuts down for any reason. * Scanner can call EventProcessorOptions.notifyOfException, which calls user code. Change notifyOfException to defensively catch any exceptions coming out of user code.
1 parent 1c70bc8 commit 0e52fd7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

azure-eventhubs-eph/src/main/java/com/microsoft/azure/eventprocessorhost/EventProcessorOptions.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import java.util.function.Consumer;
1414
import java.util.function.Function;
1515

16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
18+
1619
/***
1720
* Options affecting the behavior of the event processor host instance in general.
1821
*/
@@ -27,6 +30,8 @@ public final class EventProcessorOptions {
2730
return EventPosition.fromStartOfStream();
2831
};
2932

33+
private static final Logger TRACE_LOGGER = LoggerFactory.getLogger(EventProcessorOptions.class);
34+
3035
public EventProcessorOptions() {
3136
}
3237

@@ -212,7 +217,12 @@ void notifyOfException(String hostname, Exception exception, String action, Stri
212217
// Capture handler so it doesn't get set to null between test and use
213218
Consumer<ExceptionReceivedEventArgs> handler = this.exceptionNotificationHandler;
214219
if (handler != null) {
215-
handler.accept(new ExceptionReceivedEventArgs(hostname, exception, action, partitionId));
220+
try {
221+
handler.accept(new ExceptionReceivedEventArgs(hostname, exception, action, partitionId));
222+
}
223+
catch (Exception e) {
224+
TRACE_LOGGER.error("host " + hostname + ": caught exception from user-provided exception notification handler", e);
225+
}
216226
}
217227
}
218228

azure-eventhubs-eph/src/main/java/com/microsoft/azure/eventprocessorhost/PartitionManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ private Void scan(boolean isFirst) {
294294
.whenCompleteAsync((didSteal, e) ->
295295
{
296296
TRACE_LOGGER.debug(this.hostContext.withHost("Scanning took " + (System.currentTimeMillis() - start)));
297+
if ((e != null) && !(e instanceof ClosingException)) {
298+
TRACE_LOGGER.warn(this.hostContext.withHost("Lease scanner got exception"), e);
299+
}
297300

298301
onPartitionCheckCompleteTestHook();
299302

@@ -309,7 +312,7 @@ private Void scan(boolean isFirst) {
309312
}
310313
TRACE_LOGGER.debug(this.hostContext.withHost("Scheduling lease scanner in " + seconds));
311314
} else {
312-
TRACE_LOGGER.debug(this.hostContext.withHost("Not scheduling lease scanner due to shutdown"));
315+
TRACE_LOGGER.warn(this.hostContext.withHost("Not scheduling lease scanner due to shutdown"));
313316
}
314317
}, this.hostContext.getExecutor());
315318

0 commit comments

Comments
 (0)