Shadowsocks-windows: 非预期错误:集合已修改;可能无法执行枚举操作。

Created on 25 Nov 2016  ·  21Comments  ·  Source: shadowsocks/shadowsocks-windows

Please read Wiki carefully, especially https://github.com/shadowsocks/shadowsocks-windows/wiki/Troubleshooting.
Please answer these questions before submitting your issue. Thanks!

Version(release version or AppVeyor link)

3.3.5

Environment(Operating system, .NET Framework, etc)

Windows 7 Ultimate - 64 bit, .NET 4.6.2

Steps you have tried

无任何操作,自行弹出

What did you expect to see?

None

What did you see instead?

ss.png

Config and error log in detail (with all sensitive info masked)

软件开启但未启用系统代理,上一次关闭系统代理之前,系统代理模式为全局模式,服务器选择高可用

[2016-11-25 11:32:27] HA switching to server: jp01******
[2016-11-25 11:32:31] HA switching to server: jp06******
[2016-11-25 11:32:32] HA switching to server: jp01******
[2016-11-25 11:36:16] HA switching to server: sg03******
[2016-11-25 11:36:22] sg03****** timed out
[2016-11-25 11:36:26] sg03****** timed out
[2016-11-25 11:36:26] sg03****** timed out
[2016-11-25 11:37:15] HA switching to server: jp01******9
[2016-11-25 11:38:26] HA switching to server: sg01******9
[2016-11-25 11:38:30] [E] System.InvalidOperationException: 集合已修改;可能无法执行枚举操作。
   在 System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   在 System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   在 System.Collections.Generic.List`1.Enumerator.MoveNext()
   在 System.Linq.Enumerable.WhereListIterator`1.MoveNext()
   在 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   在 Shadowsocks.Model.StatisticsRecord..ctor(String identifier, ICollection`1 inboundSpeedRecords, ICollection`1 outboundSpeedRecords, ICollection`1 latencyRecords)
   在 Shadowsocks.Controller.AvailabilityStatistics.UpdateRecords()
   在 Shadowsocks.Controller.AvailabilityStatistics.Run(Object _)
   在 System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.TimerQueueTimer.CallCallback()
   在 System.Threading.TimerQueueTimer.Fire()
   在 System.Threading.TimerQueue.FireNextTimers()
   在 System.Threading.TimerQueue.AppDomainTimerCallback()
[2016-11-25 11:38:47] HA switching to server: jp06******
[2016-11-25 11:40:11] HA switching to server: sg02******
[2016-11-25 11:40:40] HA switching to server: jp01******
[2016-11-25 11:41:58] HA switching to server: sg03******
bug pull requests welcome

Most helpful comment

正在重做统计的部分,不过进度不是很快就是了

All 21 comments

看了下这几天好多类似的反馈,我觉得不是一句“请暂时不要使用统计功能”就能解决的。

问题是,统计功能在哪里?我是什么时候打开的?作用是什么?如何关闭?

你好,右击任务栏托盘区的纸飞机图标,选择服务器,点击统计配置,然后取消 Enable Statistics ,并点击 OK 即可。

这是默认启用的,但是会导致问题。

一般都是foreach语句玩脱了

不可能啊这个是默认禁用的啊

Odd,我看了一下,默认不启用,可能是从之前的某个版本升级上来的。

chenshaoju commented 6 hours ago
Odd,我看了一下,默认不启用,可能是从之前的某个版本升级上来的。

@chenshaoju 答对了,我是从3.0升级上来的

@limuyuan 请在观察一段时间是否还会出现该问题,如果不再出现,该问题就可以关闭了。

可用性统计是各种bug的重灾区啊。。。

正在重做统计的部分,不过进度不是很快就是了

4天过去了,我一直忘了禁用统计功能,不过那个错误提示也再没出现过

如果确定是统计功能导致的报错,那本问题应该可以关闭了

这个问题是因为多线程导致的一致性问题,可以认为具有很大的随机性。如果下次再出现请禁用统计功能以防万一。新的统计功能争取能够在下个版本上线,带来的不便还请谅解。

看起来像是List的问题,可以尝试用ConcurrentBag

看起来像是List的问题,可以尝试用ConcurrentBag

ConcurrentBag似乎是无序的吧。。。也无法用index检索
SynchronizedCollection可能更好一些

[ComVisibleAttribute(false)]
public class SynchronizedCollection<T> : IList<T>, ICollection<T>, 
    IEnumerable<T>, IEnumerable, IList, ICollection

可能引发此问题的原因:

    var id = server.Identifier();
    List<int> inboundSpeedRecords = null;
    List<int> outboundSpeedRecords = null;
    List<int> latencyRecords = null;
    _inboundSpeedRecords.TryGetValue(id, out inboundSpeedRecords);
    _outboundSpeedRecords.TryGetValue(id, out outboundSpeedRecords);
    _latencyRecords.TryGetValue(id, out latencyRecords);
    StatisticsRecord record = new StatisticsRecord(id, inboundSpeedRecords, outboundSpeedRecords, latencyRecords);

问题可能出现在最后一句代码。
虽然_inboundSpeedRecords都是ConcurrentDictionary,但取出来的值都是引用类型,StatisticsRecord()的构造函数有.ToList()操作,如果此时List内容有变更就GG

同样的问题又出现了 今天更新4.0.10 发现同样的问题又出现了。而且错误后 就自动退出了,完全不给机会设置啊。(PS:设置了也没用,不是统计的问题。)

" 在 Shadowsocks.Util.SystemProxy.Sysproxy.ParseQueryStr(String str)\r\n 在 Shadowsocks.Util.SystemProxy.Sysproxy.SetIEProxy(Boolean enable, Boolean global, String proxyServer, String pacURL)\r\n 在 Shadowsocks.Controller.SystemProxy.Update(Configuration config, Boolean forceDisable, PACServer pacSrv)\r\n 在 Shadowsocks.Controller.ShadowsocksController.Reload()\r\n 在 Shadowsocks.Program.Main()"

而且更新4.0.10 报错之后 我回到老版本也不行了。一下子所有版本都不能用了。

tim 20180523092119

最近在4.1.5也出现了,姑且按照上面说的关掉统计试一下

错误提示

最近的某个PR似乎解决了问题?

2591

Was this page helpful?
0 / 5 - 0 ratings