Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Asp.Net Core

Asp.Net Core: Fix SignalR Reconnects Losing Group Membership

- 21.11.26 - ErcanOPAK

⚙️ Asp.Net Core: Fix SignalR Reconnects Losing Group Membership

SignalR’s automatic reconnect transparently re-establishes the transport connection, but a reconnect creates a logically new connection with a new ConnectionId on the server. Group membership is keyed per-ConnectionId by default, so any earlier Groups.AddToGroupAsync calls don’t carry over — unless the application explicitly re-adds the new connection to its groups, a client that silently reconnects after a brief network blip quietly stops receiving group broadcasts.

🔎 The Problem

public class NotificationsHub : Hub
{
    public async Task JoinTeam(string teamId)
    {
        // only called once, on the very first connect from the client
        await Groups.AddToGroupAsync(Context.ConnectionId, $"team-{teamId}");
    }
    // after a transparent reconnect, ConnectionId changes but
    // JoinTeam is never called again - the new connection is
    // in no groups at all
}

✅ Fix: Re-Join Groups on Every Connect, Not Just the First

  • Re-run group-join logic inside the hub’s OnConnectedAsync for every new connection unconditionally, rather than only on the client’s very first connect, so a reconnect’s new ConnectionId gets re-added to whatever groups the user’s session should belong to.
  • Track which groups a user should be in by user identity (not ConnectionId) in your own application state, so OnConnectedAsync can look that up and restore membership regardless of whether this is a first connection or a reconnect.
  • On the client, listen for the onreconnected event and treat it as a signal to re-confirm server-side state, rather than assuming a successful reconnect means everything picked back up exactly where it left off.

🚨 Why This Is Dangerous

  • A user who appears connected but has silently fallen out of their groups will stop receiving real-time updates with no visible error, making the bug look like an intermittent, unreproducible gap in functionality rather than the deterministic reconnect behavior it actually is.

SignalR’s automatic reconnect restores the connection, not the connection’s group memberships — those have to be rebuilt explicitly, every time, because to the server a reconnect and a first connect look exactly the same.

— Backend Architect

Related posts:

ASP.NET Core: Fix Swagger Docs That Omit a Valid Endpoint Because Two Actions Share the Same Route T...

ASP.NET Core: Fix Swagger Docs That Omit a Valid Endpoint Because Two Actions Share the Same Route T...

ASP.NET Core: Fix a Keyed Service Resolution That Silently Picks the Wrong Implementation Because Tw...

ASP.NET Core: Fix a Keyed Service Resolution That Silently Picks the Wrong Implementation Because Tw...

ASP.NET Core: Fix a Rate Limiter That Blocks Legitimate Traffic Behind a Shared Proxy IP

ASP.NET Core: Fix a Rate Limiter That Blocks Legitimate Traffic Behind a Shared Proxy IP

Views: 3

Post navigation

Windows 11: Fix Snap Layouts Forgetting a Custom Grid After Sleep
JavaScript: Fix a WeakRef Target Being Collected Too Early

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (661)
  • Add Constraint to SQL Table to ensure email contains @ (619)
  • Average of all values in a column that are not zero in SQL (577)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (553)
  • Find numbers with more than two decimal places in SQL (481)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store
  • WordPress: Fix a Navigation Block Losing Submenu Items After Sync
  • Visual Studio: Fix CodeLens Reference Counts Stuck at Stale Numbers
  • C#: Fix a UTF-8 String Literal Behaving Differently in a Switch
  • Photoshop: Fix a Liquify Mesh Snapping Back on a Smart Object
  • The AI Prompt That Turns a Crash Dump Into a Short Repro Script

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com