Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to EventHub/ServiceBus error handling (#1784, #1760) #1788

Merged
merged 1 commit into from
Jul 3, 2018

Conversation

mathewc
Copy link
Member

@mathewc mathewc commented Jul 3, 2018

@mathewc mathewc requested a review from brettsam July 3, 2018 17:28
config.Queues.VisibilityTimeout = TimeSpan.FromSeconds(15);
config.Queues.MaxDequeueCount = 3;
config.LoggerFactory = new LoggerFactory().AddConsole();
while (true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will undo these changes - was using this create/dispose loop to verify my changes. Before the changes, each restart resulted in ServiceBus error logs being written, now the host restarts are all clean.

{
internal static class LogLevelExtensions
{
internal static TraceLevel ToTraceLevel(this LogLevel logLevel)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied this from the functions runtime codebase

// get the services we need to construct our binding providers
INameResolver nameResolver = context.Config.GetService<INameResolver>();
IExtensionRegistry extensions = context.Config.GetService<IExtensionRegistry>();

// register the background exception handler
var exceptionHandler = MessagingExceptionHandler.Subscribe(Config.MessageOptions, context.Trace, context.Config.LoggerFactory);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key for ServiceBus issue fix was to capture the exception handler and flow it down to the listener, so it can be unsubscribed BEFORE we abort the messaging factory.

@@ -444,6 +444,9 @@ void IExtensionConfigProvider.Initialize(ExtensionConfigContext context)
.AddConverter<byte[], EventData>(ConvertBytes2EventData)
.AddConverter<EventData, byte[]>(ConvertEventData2Bytes);

// register the background exception handler
MessagingExceptionHandler.Subscribe(_options, context.Trace, context.Config.LoggerFactory);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to unsubscribe for EventHubs - the way our listener unregisters the EPH shuts down cleanly. I had flowed it down anyways, however we don't want to unregister before we close the EPH (since any errors happening during graceful shutdown we want to log).


protected override LogLevel GetLogLevel(Exception ex)
{
if (ex is ReceiverDisconnectedException ||
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key change for the EventHub issue fix - overriding the base level determination to make these Info level rather than errors as they are now (generating CRIs)


public EventHubExceptionHandler(EventProcessorOptions options, TraceWriter traceWriter, ILoggerFactory loggerFactory = null) : base("EventProcessorHost", traceWriter, loggerFactory)
{
_options = options;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null check the options? Otherwise your subscribe/unsubscribe will NRE.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@mathewc mathewc force-pushed the logging-fix branch 2 times, most recently from 5c25c4a to c731190 Compare July 3, 2018 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants