PollySignalR 1.0.2
dotnet add package PollySignalR --version 1.0.2
NuGet\Install-Package PollySignalR -Version 1.0.2
<PackageReference Include="PollySignalR" Version="1.0.2" />
<PackageVersion Include="PollySignalR" Version="1.0.2" />
<PackageReference Include="PollySignalR" />
paket add PollySignalR --version 1.0.2
#r "nuget: PollySignalR, 1.0.2"
#:package PollySignalR@1.0.2
#addin nuget:?package=PollySignalR&version=1.0.2
#tool nuget:?package=PollySignalR&version=1.0.2
PollySignalR
Polly v8 reconnect policy for ASP.NET Core SignalR.
Drop-in replacement for WithAutomaticReconnect(TimeSpan[]) with full Polly v8 exponential back-off, jitter, configurable max retries, and max delay. Also provides StartWithResilienceAsync for resilient initial connections.
Why PollySignalR?
SignalR's built-in reconnect is limited to a fixed array of delays:
| Feature | WithAutomaticReconnect(TimeSpan[]) |
PollySignalR |
|---|---|---|
| Exponential back-off | ❌ manual | ✅ automatic |
| Jitter (reconnect storm prevention) | ❌ | ✅ |
| Configurable max retries | ❌ array length | ✅ |
| Max delay cap | ❌ last array element | ✅ |
| Linear back-off option | ❌ | ✅ |
| Infinite retries | ❌ | ✅ |
| Polly v8 pipeline for initial connect | ❌ | ✅ |
| Single line of config | ❌ | ✅ |
Installation
dotnet add package PollySignalR
Quick Start
var connection = new HubConnectionBuilder()
.WithUrl("https://example.com/hub")
.WithPollyReconnect() // exponential back-off, infinite retries, up to 60 s
.Build();
Configuration
var connection = new HubConnectionBuilder()
.WithUrl("https://example.com/hub")
.WithPollyReconnect(options =>
{
options.MaxRetries = 10; // null = infinite (default)
options.BaseDelay = TimeSpan.FromSeconds(1); // default: 1 s
options.MaxDelay = TimeSpan.FromSeconds(60); // default: 60 s
options.JitterFactor = 0.5; // ±50% noise (default)
options.BackoffType = DelayBackoffType.Exponential; // or Linear
})
.Build();
How delays are computed
delay = clamp(BaseDelay × 2^attempt, 0, MaxDelay)
+ random(−JitterFactor × BaseDelay, +JitterFactor × BaseDelay)
| Attempt | BaseDelay=1s, MaxDelay=60s |
|---|---|
| 0 | ~1 s |
| 1 | ~2 s |
| 2 | ~4 s |
| 3 | ~8 s |
| 4 | ~16 s |
| 5 | ~32 s |
| 6+ | ~60 s (capped) |
Resilient initial connection
Use StartWithResilienceAsync to apply a full Polly v8 pipeline to the first connect attempt (before automatic reconnect takes over):
var pipeline = new ResiliencePipelineBuilder()
.AddRetry(new RetryStrategyOptions
{
ShouldHandle = new PredicateBuilder().Handle<Exception>(),
MaxRetryAttempts = 5,
BackoffType = DelayBackoffType.Exponential,
Delay = TimeSpan.FromSeconds(1),
UseJitter = true,
})
.AddTimeout(new TimeoutStrategyOptions { Timeout = TimeSpan.FromSeconds(30) })
.Build();
await connection.StartWithResilienceAsync(pipeline);
Blazor WebAssembly
// Program.cs
builder.Services.AddSingleton(sp =>
new HubConnectionBuilder()
.WithUrl(builder.HostEnvironment.BaseAddress + "chathub")
.WithPollyReconnect(o =>
{
o.BaseDelay = TimeSpan.FromSeconds(2);
o.MaxDelay = TimeSpan.FromSeconds(120);
o.MaxRetries = null; // never give up
})
.Build());
Related Packages
| Package | Downloads | Description |
|---|---|---|
| PollyHealthChecks | ASP.NET Core health checks for Polly v8 circuit breakers — expose circuit-breaker state (Closed, HalfOpen, Open, Isolated) as /health endpoint responses | |
| PollyBackoff | Backoff delay strategies for Polly v8 resilience pipelines | |
| PollyGrpc | Polly v8 resilience interceptor for gRPC | |
| PollyEFCore | Polly v8 resilience pipelines for Entity Framework Core — wrap every EF Core query and SaveChanges with retry, timeout and circuit-breaker via a single AddPollyResilience() call | |
| PollyMailKit | Polly v8 resilience pipelines for MailKit — retry, timeout, and circuit-breaker for SmtpClient.SendAsync and any MailKit SMTP operation | |
| PollyMassTransit | Polly v8 resilience pipelines for MassTransit — retry, timeout, and circuit-breaker for IBus.Publish and ISendEndpointProvider.Send | |
| PollyOpenAI | Polly v8 resilience for OpenAI and Azure OpenAI API calls | |
| PollyAzureEventHub | Polly v8 resilience pipelines for Azure Event Hubs — retry, timeout, and circuit-breaker for EventHubProducerClient and EventHubConsumerClient | |
| PollyElasticsearch | Polly v8 resilience pipelines for Elastic.Clients.Elasticsearch 8+ — retry, timeout, and circuit-breaker for any Elasticsearch operation, plus a built-in ElasticTransientErrors predicate covering rate limiting (429), service unavailability (503), gateway timeouts (504), and connection failures | |
| PollyHangfire | Polly v8 resilience pipelines for Hangfire — retry, timeout, and circuit-breaker for IBackgroundJobClient.Enqueue and Schedule | |
| PollySendGrid | Polly v8 resilience pipelines for SendGrid — retry, timeout, and circuit-breaker for ISendGridClient.SendEmailAsync | |
| PollyMediatR | Polly v8 resilience pipelines for MediatR — add retry, timeout, circuit-breaker, rate-limiting, hedging, and chaos engineering to any MediatR request handler with a single line of DI registration | |
| PollyAzureKeyVault | Polly v8 resilience pipelines for Azure Key Vault — retry, timeout, and circuit-breaker for SecretClient, KeyClient, and CertificateClient | |
| PollyAzureQueueStorage | Polly v8 resilience pipelines for Azure Queue Storage — retry, timeout, and circuit-breaker for Azure.Storage.Queues QueueClient | |
| PollyRedis | Polly v8 resilience for StackExchange.Redis | |
| PollyAzureServiceBus | Polly v8 resilience for Azure Service Bus — retry, circuit breaker, and timeout for sending and receiving messages | |
| PollyKafka | Polly v8 resilience for Confluent.Kafka — retry, circuit breaker, and timeout for producers and consumers | |
| PollyAzureTableStorage | Polly v8 resilience pipelines for Azure Table Storage — retry, timeout, and circuit-breaker for Azure.Data.Tables TableClient | |
| PollyChaos | Chaos engineering and fault-injection resilience strategies for Polly v8 pipelines |
💼 Need .NET consulting?
The author of this package is available for consulting on Polly v8 resilience, Azure cloud architecture, and clean .NET design.
→ solidqualitysolutions.com · LinkedIn
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.SignalR.Client (>= 8.0.29)
- Polly.Core (>= 8.7.0)
-
net8.0
- Microsoft.AspNetCore.SignalR.Client (>= 8.0.29)
- Polly.Core (>= 8.7.0)
-
net9.0
- Microsoft.AspNetCore.SignalR.Client (>= 8.0.29)
- Polly.Core (>= 8.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.0.2: Add net10.0 target framework support. 1.0.1: Fix package icon (was showing an incorrect/placeholder image). Initial release. Polly v8 exponential back-off reconnect policy for SignalR HubConnection, plus StartWithResilienceAsync for resilient initial connections.