From efbe4841641c48842a87ecc0c2cd66a10d09a154 Mon Sep 17 00:00:00 2001 From: Bob Langley Date: Fri, 5 Jun 2026 22:11:55 -0700 Subject: [PATCH 1/2] Document bridge critical error handling --- Snippets/Bridge/Bridge_5/Configuration.cs | 26 +++++++++++++++++++ nservicebus/bridge/configuration.md | 5 ++-- ...ical-error-action_bridge_[5.1,).partial.md | 7 +++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 nservicebus/bridge/configuration_critical-error-action_bridge_[5.1,).partial.md diff --git a/Snippets/Bridge/Bridge_5/Configuration.cs b/Snippets/Bridge/Bridge_5/Configuration.cs index fe47e7d71d6..0c8b420f8c1 100644 --- a/Snippets/Bridge/Bridge_5/Configuration.cs +++ b/Snippets/Bridge/Bridge_5/Configuration.cs @@ -47,6 +47,32 @@ await Host.CreateDefaultBuilder() #endregion } + public void CriticalErrorAction() + { + var bridgeConfiguration = new BridgeConfiguration(); + + #region bridge-critical-error-action + + bridgeConfiguration.DefineCriticalErrorAction(async (context, cancellationToken) => + { + var fatalMessage = + $"The following critical error was encountered:{Environment.NewLine}" + + $"{context.Error}{Environment.NewLine}" + + "The bridge is shutting down."; + + try + { + await context.Stop(cancellationToken); + } + finally + { + Environment.FailFast(fatalMessage, context.Exception); + } + }); + + #endregion + } + public async Task EndpointRegistration() { #region endpoint-registration diff --git a/nservicebus/bridge/configuration.md b/nservicebus/bridge/configuration.md index 22b4683079d..f3f92093769 100644 --- a/nservicebus/bridge/configuration.md +++ b/nservicebus/bridge/configuration.md @@ -2,7 +2,7 @@ title: Bridge configuration options summary: Configuration options for the messaging bridge. component: Bridge -reviewed: 2026-05-13 +reviewed: 2026-06-01 --- ## Hosting @@ -15,6 +15,8 @@ The overload that accepts a [`HostBuilderContext`](https://learn.microsoft.com/e snippet: generic-host-builder-context +partial: critical-error-action + ## Registering endpoints If a logical endpoint communicates with other endpoints that use a different transport, it must be registered with the bridge. Endpoints are registered with the bridge on the transport they run on. The bridge then creates a proxy endpoint on each transport that needs to be bridged. @@ -157,4 +159,3 @@ partial: monitoring - diff --git a/nservicebus/bridge/configuration_critical-error-action_bridge_[5.1,).partial.md b/nservicebus/bridge/configuration_critical-error-action_bridge_[5.1,).partial.md new file mode 100644 index 00000000000..5e96d5b450d --- /dev/null +++ b/nservicebus/bridge/configuration_critical-error-action_bridge_[5.1,).partial.md @@ -0,0 +1,7 @@ +## Critical error handling + +A bridge can encounter a [critical error](/nservicebus/hosting/critical-errors.md) when a transport cannot recover from an infrastructure failure. Use `DefineCriticalErrorAction` to stop the affected bridge endpoint and terminate the process: + +snippet: bridge-critical-error-action + +Configure the hosting environment to [restart the terminated process](/nservicebus/hosting/critical-errors.md#how-do-i-deal-with-persistent-critical-errors-terminate-and-restart-the-process). Calling `context.Stop` without terminating the process stops only the bridge endpoint that raised the critical error. From 2e1d396fe5ca6ee615a3f3353fbde41deab3cddf Mon Sep 17 00:00:00 2001 From: Tamara Rivera Date: Mon, 8 Jun 2026 17:34:51 -0700 Subject: [PATCH 2/2] Update critical error handling for version 5.1 --- ... configuration_critical-error-action_bridge_[5,).partial.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename nservicebus/bridge/{configuration_critical-error-action_bridge_[5.1,).partial.md => configuration_critical-error-action_bridge_[5,).partial.md} (77%) diff --git a/nservicebus/bridge/configuration_critical-error-action_bridge_[5.1,).partial.md b/nservicebus/bridge/configuration_critical-error-action_bridge_[5,).partial.md similarity index 77% rename from nservicebus/bridge/configuration_critical-error-action_bridge_[5.1,).partial.md rename to nservicebus/bridge/configuration_critical-error-action_bridge_[5,).partial.md index 5e96d5b450d..173d8d61391 100644 --- a/nservicebus/bridge/configuration_critical-error-action_bridge_[5.1,).partial.md +++ b/nservicebus/bridge/configuration_critical-error-action_bridge_[5,).partial.md @@ -1,6 +1,6 @@ ## Critical error handling -A bridge can encounter a [critical error](/nservicebus/hosting/critical-errors.md) when a transport cannot recover from an infrastructure failure. Use `DefineCriticalErrorAction` to stop the affected bridge endpoint and terminate the process: +A bridge can encounter a [critical error](/nservicebus/hosting/critical-errors.md) when a transport cannot recover from an infrastructure failure. Starting with version 5.1, `DefineCriticalErrorAction` can be used to stop the affected bridge endpoint and terminate the process: snippet: bridge-critical-error-action