Skip to content

Commit 1e1c347

Browse files
Olof Andreassenmattqs
authored andcommitted
* Fixed bug where callin Cleanup sometimes caused a crash due to modifying a collection that was being used in a enumerator. (#106)
1 parent 4a3194a commit 1e1c347

3 files changed

Lines changed: 11 additions & 14 deletions

File tree

Src/SocketIoClientDotNet.net45/Client/Manager.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Quobject.EngineIoClientDotNet.Modules;
44
using Quobject.EngineIoClientDotNet.Thread;
55
using System;
6+
using System.Collections.Concurrent;
67
using System.Collections.Generic;
78
using System.Text;
89

@@ -45,7 +46,7 @@ public enum ReadyStateEnum
4546
private int Attempts;
4647
private Uri Uri;
4748
private List<Parser.Packet> PacketBuffer;
48-
private Queue<On.IHandle> Subs;
49+
private ConcurrentQueue<On.IHandle> Subs;
4950
private Quobject.EngineIoClientDotNet.Client.Socket.Options Opts;
5051
private bool AutoConnect;
5152
private HashSet<Socket> OpeningSockets;
@@ -87,7 +88,7 @@ public Manager(Uri uri, Options opts)
8788
}
8889
this.Opts = opts;
8990
this.Nsps = ImmutableDictionary.Create<string, Socket>();
90-
this.Subs = new Queue<On.IHandle>();
91+
this.Subs = new ConcurrentQueue<On.IHandle>();
9192
this.Reconnection(opts.Reconnection);
9293
this.ReconnectionAttempts(opts.ReconnectionAttempts != 0 ? opts.ReconnectionAttempts : int.MaxValue);
9394
this.ReconnectionDelay(opts.ReconnectionDelay != 0 ? opts.ReconnectionDelay : 1000);
@@ -394,11 +395,11 @@ private void ProcessPacketQueue()
394395

395396
private void Cleanup()
396397
{
398+
// Concurrent-queue makes a copy when calling GetEnumerator
399+
// which protects it from any changes done in Subs while calling destroy
397400
foreach (var sub in Subs)
398401
{
399-
lock (Subs) {
400-
sub.Destroy();
401-
}
402+
sub.Destroy();
402403
}
403404
}
404405

Src/SocketIoClientDotNet.net45/SocketIoClientDotNet.net45.csproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,19 @@
3131
</PropertyGroup>
3232
<ItemGroup>
3333
<Reference Include="EngineIoClientDotNet, Version=0.10.1.0, Culture=neutral, processorArchitecture=MSIL">
34-
<HintPath>packages\EngineIoClientDotNet.0.10.1-beta2\lib\net45\EngineIoClientDotNet.dll</HintPath>
35-
<Private>True</Private>
34+
<HintPath>..\..\..\packages\EngineIoClientDotNet.0.10.1-beta2\lib\net45\EngineIoClientDotNet.dll</HintPath>
3635
</Reference>
3736
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
38-
<HintPath>packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
39-
<Private>True</Private>
37+
<HintPath>..\..\..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
4038
</Reference>
4139
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.6, Culture=neutral, processorArchitecture=MSIL">
42-
<HintPath>packages\SuperSocket.ClientEngine.Core.0.8.0.6\lib\net45\SuperSocket.ClientEngine.dll</HintPath>
43-
<Private>True</Private>
40+
<HintPath>..\..\..\packages\SuperSocket.ClientEngine.Core.0.8.0.6\lib\net45\SuperSocket.ClientEngine.dll</HintPath>
4441
</Reference>
4542
<Reference Include="System" />
4643
<Reference Include="System.Core" />
4744
<Reference Include="System.Web" />
4845
<Reference Include="WebSocket4Net, Version=0.15.0.0, Culture=neutral, processorArchitecture=MSIL">
49-
<HintPath>packages\WebSocket4Net.0.15.0-beta6\lib\net45\WebSocket4Net.dll</HintPath>
50-
<Private>True</Private>
46+
<HintPath>..\..\..\packages\WebSocket4Net.0.15.0-beta6\lib\net45\WebSocket4Net.dll</HintPath>
5147
</Reference>
5248
</ItemGroup>
5349
<ItemGroup>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="EngineIoClientDotNet" version="0.10.1-beta2" targetFramework="net45" />
4-
<package id="Newtonsoft.Json" version="10.0.1" targetFramework="net45" />
4+
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
55
<package id="SuperSocket.ClientEngine.Core" version="0.8.0.6" targetFramework="net45" />
66
<package id="WebSocket4Net" version="0.15.0-beta6" targetFramework="net45" />
77
</packages>

0 commit comments

Comments
 (0)