I'm using SignalR client version 2.2.0 nuget.
this._connection = new HubConnection(this._url);
this._connection.Closed += this.ConnectionOnClosed;
this._connection.Error += this.ConnectionOnError;
ServicePointManager.DefaultConnectionLimit = 250;
this._client = this._connection.CreateHubProxy(HubName);
this._connection.Start(new WebSocketTransport()).Wait();
Then I reuse the client every time (multi-threaded):
client.Invoke<bool>(nameof(this.AddIfNotExists), key, data, expireAfter)
Parallel.For(
0,
50000,
new ParallelOptions
{
MaxDegreeOfParallelism = 10,
},
async (i) =>
{
var result = await client.ExecuteDistributedAsync(
(i % 2).ToString(),
TimeSpan.FromSeconds(5),
async () =>
{
await Task.Delay(500);
return $"Done: {i} [{(i % 2)}]";
});
Console.WriteLine("--->" + (result ?? "TIMEOUT:" + i));
});
This crashes almost immediately (1st addifnotexist works and then the next 8 it crashes). From what I've read everywhere the IHubProxy is supposed to be thread-safe... Any suggestions?