PollySignalR 1.0.1
dotnet add package PollySignalR --version 1.0.1
NuGet\Install-Package PollySignalR -Version 1.0.1
<PackageReference Include="PollySignalR" Version="1.0.1" />
<PackageVersion Include="PollySignalR" Version="1.0.1" />
<PackageReference Include="PollySignalR" />
paket add PollySignalR --version 1.0.1
#r "nuget: PollySignalR, 1.0.1"
#:package PollySignalR@1.0.1
#addin nuget:?package=PollySignalR&version=1.0.1
#tool nuget:?package=PollySignalR&version=1.0.1
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 |
|---|---|---|
| PollyOpenAI | Polly v8 resilience for OpenAI and Azure OpenAI API calls | |
| PollyRedis | Polly v8 resilience for StackExchange.Redis | |
| PollyEFCore | Polly v8 resilience for EF Core queries and SaveChanges | |
| PollyHealthChecks | ASP.NET Core health checks for Polly v8 circuit breakers | |
| PollyChaos | Chaos engineering / fault injection for Polly v8 | |
| PollyMediatR | Polly v8 pipelines for MediatR request handlers | |
| PollyElasticsearch | Polly v8 for Elastic.Clients.Elasticsearch | |
| PollyAzureKeyVault | Polly v8 for Azure Key Vault | |
| PollySendGrid | Polly v8 for SendGrid | |
| PollyMassTransit | Polly v8 for MassTransit | |
| PollyAzureTableStorage | Polly v8 for Azure Table Storage | |
| PollyMailKit | MailKit SMTP email client | |
| PollyAzureQueueStorage | Azure Queue Storage QueueClient | |
| PollyHangfire | Hangfire IBackgroundJobClient | |
| PollyBackoff | Custom back-off strategies for Polly v8 |
| PollyGrpc | Polly v8 resilience (retry, CB, timeout) for gRPC .NET clients via Interceptor | | PollyKafka | Polly v8 resilience (retry, CB, timeout) for Confluent.Kafka producers and consumers | | PollyAzureEventHub | Polly v8 for Azure Event Hubs | | PollyAzureServiceBus | Polly v8 resilience (retry, CB, timeout) for Azure Service Bus senders and receivers |
💼 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 was computed. 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. |
-
net8.0
- Microsoft.AspNetCore.SignalR.Client (>= 8.0.28)
- Polly.Core (>= 8.7.0)
-
net9.0
- Microsoft.AspNetCore.SignalR.Client (>= 8.0.28)
- 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.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.