dotnet / dotnet/aspnetcore

HttpConnectionContext.TickHeartbeat() in SignalR ticks after the context is disposed, causing runtime errors when accessing context from heartbeat handlers

Open
#60,631 5 comments 0 reactions 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

HubCallerContext is already disposed, its getter throws an error instead of doing anything useful (like returning a context where someone could check if it's disposed before trying to use it). When users attach OnHeartbeat handlers, I think it's fair to expect that the framework will stop calling them once the session is disposed. However, it seems like sometimes the heartbeats continue after this point, and this generates runtime errors because who wraps their property access attempts in a try/catch.

![Image](https://github.com/user-attachments/assets/4af9e58e-506e-49ea-b415-342d85d71ada)

### Expected Behavior

Heartbeat handlers are no longer called after session dispose, or accessor does not throw an error and Context has a property that devs can check themselves.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.