-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Occasionally, I would get exceptions when assigning new events to the _bindings dictionary in Channel.cs .
With the attached code, the error would appear after approx. 1000 pushes.
These exceptions happen because the socket replies are received on another thread. The _bindings dictionary is not thread safe so adds and removes crash.
So, in Channel.cs, change the type of SubscriptionTable to ConcurrentDictionary:
using SubscriptionTable = System.Collections.Concurrent.ConcurrentDictionary<string, System.Collections.Generic.List<Phoenix.ChannelSubscription>>;
and use TryRemove on _bindings:
public bool Off(string anyEvent) => _bindings.TryRemove(anyEvent, out _);
I've tested the updated code with tens of thousands of pushes and it doesn't crash now:
