Should I override critical error handling or not?


(Calvin) #1

I found conflicting information in this doc: https://docs.particular.net/nservicebus/hosting/critical-errors?version=core_7

Under “Default Behavior” section is says
"The default behavior is to log the exception and keep retrying indefinitely."

Then under “When to override the default critical error action” section, it also says
"The default action should always be overridden when self-hosting NServiceBus, as by default when a critical error occurs the endpoint will stop without exiting the process."

My goal is that I don’t want my endpoints (hosted in web apps) be stopped by critical errors. Because my transport may eventually back online and I want my endpoints to continue to send messages without having to restart them.

I did a quick test - shutting down RabbitMQ then turning it back on. Without overriding the critical errors, my endpoints were able to send message again - I saw the circuit breaker “is not disarmed” in the log. So I don’t have to override it then?

Thanks!


(Sean Feldman) #2

Hi Calvin,

Overriding critical error should be used when you need to take a drastic action. For example, you want to kill the hosting process used to host the endpoint to allow the system to restart the host. Otherwise, in scenario like yours, you don’t need to override it.


(Calvin) #3

Thank you Sean for the confirmation.


(Ramon Smits) #4

Critical error callback always needs to be overridden when self-hosting on NServiceBus versions prior to version 7. The documentation you are linking and quoting is version 7. If you are indeed using version 7 then you do not have to do anything but if you are using an older version you should add a critical error callback.

Thanks for mentioning the inconsistency with the “When to override the default critical error action” action as that needs to be updated with the behavior for version 7.

– Ramon