You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the SocketIoClientDotNet in a WPF (.NET 4.5) application. I'm calling the Emit method in an async function, and it's interchanging the callbacks indeterminently.
I forked the repository and looked after the problem, it's in the Emit method, where the Ids variable is incremented. It is not threadsafe, thus two packets could have the same Id.
I solved this problem with this simple modification:
`public Emitter Emit(string eventString, IAck ack, params object[] args)
{
var log = LogManager.GetLogger(Global.CallerName());
var _args = new List<object> { eventString };
if (args != null)
{
_args.AddRange(args);
}
var jarray = new JArray(_args);
var packet = new Packet(Parser.Parser.EVENT, jarray);
packet.Id = Interlocked.Increment(ref Ids);
log.Info(string.Format("emitting packet with ack id {0}", packet.Id));
Acks = Acks.Add(packet.Id, ack);
Packet(packet);
return this;
}`
The key part is:
packet.Id = Interlocked.Increment(ref Ids);
It is a thread safe way to increment a variable.
The text was updated successfully, but these errors were encountered:
I'm using the SocketIoClientDotNet in a WPF (.NET 4.5) application. I'm calling the Emit method in an async function, and it's interchanging the callbacks indeterminently.
I forked the repository and looked after the problem, it's in the Emit method, where the Ids variable is incremented. It is not threadsafe, thus two packets could have the same Id.
I solved this problem with this simple modification:
`public Emitter Emit(string eventString, IAck ack, params object[] args)
{
var log = LogManager.GetLogger(Global.CallerName());
}`
The key part is:
packet.Id = Interlocked.Increment(ref Ids);
It is a thread safe way to increment a variable.
The text was updated successfully, but these errors were encountered: