We are seeing a very strange issue with our signalR client that results in complete port exhaustion on the machine running the code. Over 16000 ports end up in the Close_Wait state.
The logs show that the Closed handle is firing several hundred times a second.
The program can run fine for hours or days before the issue occurs.
How is it possible to make the Closed handle in the code below fire continuously until all ports are exhausted?
using Microsoft.AspNet.SignalR.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApp
{
public class TestEvents
{
private HubConnection _connection;
private IHubProxy<ITestHub, ITestClientContract> Proxy;
public TestEvents()
{
string url = "http://myserver/MySignalRHub";
_connection = new HubConnection(url);
_connection.Closed += HubConnectionOnClosed;
_connection.Reconnected += HubConnectionOnReconnected;
_connection.Reconnecting += HubConnectionOnReconnecting;
Proxy = _connection.CreateHubProxy<ITestHub, ITestClientContract>("TestHub");
}
public async Task Start()
{
await _connection.Start();
var result = await Proxy.CallAsync(h => h.TestMethod("test"));
Console.WriteLine($"Got {result} from connection {_connection.ConnectionId}");
}
private async void HubConnectionOnClosed()
{
Console.WriteLine("Closed");
try
{
await _connection.Start();
}
catch(Exception ex)
{
Console.WriteLine("Error");
}
}
private async void HubConnectionOnReconnected()
{
Console.WriteLine("Reconnected");
}
private async void HubConnectionOnReconnecting()
{
Console.WriteLine("Reconnecting");
}
}
}