I have a simple Hub
running in Azure, that I have working perfectly from a console app in Windows.
I just built a simple test Xamarin.iOS app, and it is giving some strange behavior.
- Randomly on LTE/Wifi or Simulator/Device - invoking a hub method fails with
There was an error invoking Hub method X
- Randomly about 50% - everything works perfectly just like the console app on Windows - the two are even sending messages to one another
I tested this on an iPhone 5S and iPhone 4S for devices.
Any ideas on why this would happen? I'm using the Portable NuGet package on version 2.0.0.
UPDATE:
Here is what I get when I enable tracing (I blanked out my domain):
2013-11-25 07:47:48.204 MyApp[5163:80b] 13:47:48.1865420 - null - ChangeState(Disconnected, Connecting)
2013-11-25 07:47:49.025 MyApp[5163:6b03] 13:47:49.0247930 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: GET http://mydomain.cloudapp.net/signalr/connect?transport=serverSentEvents&connectionToken=pVF6LN7KBOem7Ng2hrhx6dSByFe%2BxCr4u6RlY5V%2FtKf%2BHmOoJD5DfVpMySiUuDOaiIPlHI%2FtliqvuddvcDxnZQqi9tIYAxuyZOjYSG%2B9%2Fnx%2FQ%2B6m&connectionData=[{"Name":"MainHub"}]&noCache=c3d54c1d-ee78-49cc-85b4-2c87a024c32a
2013-11-25 07:47:49.203 MyApp[5163:6b03] 13:47:49.2023660 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: initialized)
2013-11-25 07:47:49.319 MyApp[5163:6b03] 13:47:49.3189120 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {"C":"s-0,CF9","S":1,"M":[]})
2013-11-25 07:47:49.332 MyApp[5163:6b03] 13:47:49.3318670 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - ChangeState(Connecting, Connected)
2013-11-25 07:47:49.634 MyApp[5163:6b03] 13:47:49.6339640 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {"C":"s-0,CFA","G":"54eYUWzlKXr9ezIoP1rZvj4DOQ00lfpXZ62PV+HwgzqCvgET2otfFNud1KzX24MjGplzkOwpyzqrVJ1jffBMyWppsDt9Tl+D25btqsxJWt6bBg3v4YfwobBKbpZaScgk/gPp5w==","M":[]})
2013-11-25 07:47:49.703 MyApp[5163:6b03] 13:47:49.7029070 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {"C":"s-0,CFB","M":[]})
2013-11-25 07:47:58.090 MyApp[5163:6b03] 13:47:58.0894910 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {})
2013-11-25 07:48:08.108 MyApp[5163:6b03] 13:48:08.1084000 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {})
2013-11-25 07:48:18.118 MyApp[5163:6b03] 13:48:18.1178390 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - SSE: OnMessage(Data: {})
2013-11-25 07:48:22.097 MyApp[5163:6b03] 13:48:22.0968150 - d84a25b3-b426-4f0b-b4bc-7d170e3c1bd9 - OnMessage({"I":"0","E":"There was an error invoking Hub method 'MainHub.SignOn'."})
The empty OnMessage
, will continue to print every so often after the failure.
UPDATE #2
After testing and further inspection, it seems to be more likely random than related to LTE vs Wifi. To recap, everything works fine running on my machine locally. Just not when deployed to Azure. Basically invoking a hub method will timeout, on random occurrences.
Here are a few things I've done that have made the issue more rare, but it still occurs:
- Force
LongPollingTransport
, no matter what - Add a
Task.Delay
in between a successfulStart
and the firstInvoke
I set EnableDetailedErrors
to true
on the server, and this seems to be what happens server side:
Error in SignOn: System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MyNamespace.MainHub.<SignOn>d__0.MoveNext(); TraceSource 'w3wp.exe' event
Which, I think is just related to the client giving up. I saw some Github issues related to this on Azure, but they are marked as closed...
UPDATE #3
On a whim, I deployed this to the standard Azure websites section instead of Cloud Services. Everything worked normally after that. Any ideas why? I can use Azure websites for this obviously, but why won't it work as a cloud service?
For now, the solution is to use Azure websites instead of cloud services.
When I have time, I will create a repro and submit it to the SignalR Github issues page. Should be able to do that later this week.