I have a .NET WinService. It successfully opens a connection to a Hub. The problem I have is that every 2 seconds connection_StateChanged is fired and is reconnecting all the time. I dont receive any errors and I dont know why it behaves this way. Is there
any way to troubleshoot disconnections and reconnections?
That's not a solution to anything but to force server sent events. Do you know why it was falling back to longpolling? Did you install fiddler? Do you look at the trace? It should only fallback if it times out trying to connect in the first place. When you
say it was reconnecting every 2 seconds did you mean 2 minutes? If so that's by design as longpolling connections timeout and reconnect after 2 minutes to avoid being forcibly closed by load balancers and network proxies that hate idle traffic.
When I say 2 seconds I mean 2 seconds not two minutes. And I dont understand why using long polling for a .NET web service instead of server events is a bad idea.
It is not a bad idea thats' the point. That's why I wanted you to use fiddler to see why the request was ending. It shouldn't happen and I'm interested to know what causes the issue.
pantonis
Member
328 Points
260 Posts
Reconnecting state
Jan 23, 2013 08:18 AM|LINK
I have a .NET WinService. It successfully opens a connection to a Hub. The problem I have is that every 2 seconds connection_StateChanged is fired and is reconnecting all the time. I dont receive any errors and I dont know why it behaves this way. Is there any way to troubleshoot disconnections and reconnections?
Thanks
Please mark this post as answer if it helped you solve your problem
davidfowl
Contributor
2697 Points
610 Posts
Microsoft
Re: Reconnecting state
Jan 23, 2013 10:49 AM|LINK
Try using fiddler. Also what transport is being used? You can turn logging on the server side and collect a trace. See how to do that here:
https://github.com/SignalR/SignalR/blob/master/samples/Microsoft.AspNet.SignalR.Hosting.AspNet.Samples/Web.config#L29
Senior SDE, ASP.NET Team, Microsoft
pantonis
Member
328 Points
260 Posts
Re: Reconnecting state
Jan 23, 2013 11:05 AM|LINK
Maybe that's the issue. Is the .NET Client code by default using Long Polling. Is there any way to enforce it to use WebSockets?
Please mark this post as answer if it helped you solve your problem
pantonis
Member
328 Points
260 Posts
Re: Reconnecting state
Jan 23, 2013 11:53 AM|LINK
Yes that was the issue. I forced it to use ServerSentEvents. Heres how I did it for anyone experiencing the same issue
HubConnection connection = new HubConnection("http://www.mysite.com"); connection.Start(new Microsoft.AspNet.SignalR.Client.Transports.ServerSentEventsTransport());Please mark this post as answer if it helped you solve your problem
davidfowl
Contributor
2697 Points
610 Posts
Microsoft
Re: Reconnecting state
Jan 23, 2013 03:58 PM|LINK
That's not a solution to anything but to force server sent events. Do you know why it was falling back to longpolling? Did you install fiddler? Do you look at the trace? It should only fallback if it times out trying to connect in the first place. When you say it was reconnecting every 2 seconds did you mean 2 minutes? If so that's by design as longpolling connections timeout and reconnect after 2 minutes to avoid being forcibly closed by load balancers and network proxies that hate idle traffic.
Senior SDE, ASP.NET Team, Microsoft
pantonis
Member
328 Points
260 Posts
Re: Reconnecting state
Jan 24, 2013 06:18 AM|LINK
When I say 2 seconds I mean 2 seconds not two minutes. And I dont understand why using long polling for a .NET web service instead of server events is a bad idea.
Please mark this post as answer if it helped you solve your problem
davidfowl
Contributor
2697 Points
610 Posts
Microsoft
Re: Reconnecting state
Jan 24, 2013 06:23 AM|LINK
It is not a bad idea thats' the point. That's why I wanted you to use fiddler to see why the request was ending. It shouldn't happen and I'm interested to know what causes the issue.
Senior SDE, ASP.NET Team, Microsoft
pantonis
Member
328 Points
260 Posts
Re: Reconnecting state
Jan 24, 2013 06:27 AM|LINK
I cannot capture any traffic using Fiddler from my windows service. I have the trace log file if you want but I can only send it to you in private.
Please mark this post as answer if it helped you solve your problem
davidfowl
Contributor
2697 Points
610 Posts
Microsoft
Re: Reconnecting state
Jan 25, 2013 07:16 PM|LINK
Sure
Senior SDE, ASP.NET Team, Microsoft