Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about HttpContext and SignalR #4623

Open
smedotnet opened this issue Mar 10, 2022 · 1 comment
Open

Question about HttpContext and SignalR #4623

smedotnet opened this issue Mar 10, 2022 · 1 comment

Comments

@smedotnet
Copy link

Hi,

I'm here to ask a question about the SignalR project so it's really an issue, I don't know if it's correct place to ask that. Feel free to close it if it's not.

I have noticed something with the .NET Framework SignalR implementation, i'm using the latest version (2.41.0) : Sometimes the HttpContext.Current is not null and sometimes it's null. For even like OnReconnected, OnDisconnected it seems to always be null, but when actually executing a method of a giving hub it seems to not be null (so the HttpContext.Current is filled). It's important to me to confirm that because i'm using Castle Windsor as a DI container, and i registered my Services as HybridPerWebRequestTransient (when HttpContext exists the lifestyle will be PerWebRequest and where not it will be Transient). And in production we noticed some memory leak because of that : Transient object are never released by castle because castle doesn't know where to release them. Well again it's not a SignalR issue, i would say.

So my question is : Can you please confirm me that the HttpContext.Current is only set/filled/not null only when calling a method of a Hub, and it's not set/not filled/null on events like OnReconnected and OnDisconnected of the Hub ... Also if can someone tell my why that would be great.

Thank you for reading me !

@BrennanConroy
Copy link
Member

Generally, you should be using Context.Request.GetHttpContext in your Hub: https://learn.microsoft.com/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server#how-to-get-information-about-the-client-from-the-context-property

With the above method, you should have access to the HttpContext inside OnDisconnected and OnReconnected since we capture the request on connection start.

return TaskAsyncHelper.FromMethod(() => OnDisconnected(context.Request, connectionId, stopCalled: clean).OrEmpty());

Can't comment on the HybridPerWebRequestTransient stuff, not familiar with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants