I am running a very simple signalr server hosted through Owin on an ubuntu 14.04 server, mono 3.2.8. (code below).
Connect / Disconnect works fine both on a remote Windows server and when deploying bits on a Linux server. But when the client dies unexpectedly, and does not tell signalr that it is disconnecting, this is when I get an infinite SocketException only on the linux server. The Windows server shuts down the client after about 30 seconds or so, but the linux server outputs a socket pivot (also lower) every 10 seconds or so forever.
How to make the linux server behave like a Windows server when running the same code, disconnect the user after the set timeout and not cause sockets?
Server Code:
using System; using System.Threading.Tasks; using Microsoft.AspNet.SignalR; using Owin; namespace signalrtestserver { class Program { static void Main(string[] args) { var uri = System.Configuration.ConfigurationManager.AppSettings["startup_uri"] ?? "http://*:7890"; using (Microsoft.Owin.Hosting.WebApp.Start<Startup>(uri)) { Console.WriteLine(string.Format("Server started on {0}. Press enter to close.", uri)); Console.ReadLine(); } } } class Startup { static Hub hub; public void Configuration(IAppBuilder app) { app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); var configuration = new HubConfiguration(); configuration.EnableDetailedErrors = true; app.MapSignalR("/signalr", configuration); hub = new MyHub(); } } public class MyHub : Hub { public override Task OnConnected() { Console.WriteLine(Context.ConnectionId + " connected"); return base.OnConnected(); } public override Task OnDisconnected() { Console.WriteLine(Context.ConnectionId + " disconnected"); return base.OnDisconnected(); } public override Task OnReconnected() { Console.WriteLine(Context.ConnectionId + " reconnected"); return base.OnReconnected(); } } }
Client code:
using System; using System.Net; using Microsoft.AspNet.SignalR.Client; namespace signalrconnection { class Program { static void Main(string[] args) { var uri = System.Configuration.ConfigurationManager.AppSettings["signalr_uri"] ?? "http://localhost:7890/signalr"; ServicePointManager.DefaultConnectionLimit = 10; var hubConnection = new HubConnection(uri, false); hubConnection.StateChanged += stateChange => Console.WriteLine(string.Format("SignalR {0} >> {1} ({2})", stateChange.OldState, stateChange.NewState, hubConnection.Transport == null ? "<<null>>" : hubConnection.Transport.Name)); var hubProxy = hubConnection.CreateHubProxy("MyHub"); hubConnection.Start(); Console.WriteLine("Press enter to die..."); Console.ReadLine();
Unsuccessful one-block exception:
{path-to-project}/Microsoft.AspNet.SignalR.Core.dll Error : 0 : SignalR exception thrown by Task: System.AggregateException: One or more errors occured ---> System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException: Connection reset by peer at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in <filename unknown>:0 at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0 at System.Net.ResponseStream.InternalWrite (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 at System.Net.ResponseStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 at Microsoft.Owin.Host.HttpListener.RequestProcessing.ExceptionFilterStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- --> (Inner exception 0) System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException: Connection reset by peer at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00000] in <filename unknown>:0 at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0 at System.Net.ResponseStream.InternalWrite (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 at System.Net.ResponseStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 at Microsoft.Owin.Host.HttpListener.RequestProcessing.ExceptionFilterStream.Write (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
Any help would be greatly appreciated. Thanks in advance!