msasanmh / SecureDNSClient

A DNS Client Supporting DNSCrypt, Anonymized DNSCrypt, DoH, DoT, UDP And TCP.
https://msasanmh.github.io/SecureDNSClient/
GNU General Public License v3.0
814 stars 80 forks source link

Cross Threading on Normal Dictionary? #72

Closed Masoud-Kazemi closed 1 year ago

Masoud-Kazemi commented 1 year ago

After Working for while Proxy will stop working, i did not check the code 🙇🏻 MsmhTools/MsmhTools/HTTPProxyServer/TunnelManager.cs <<<<

Unhandled exception. System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct. at System.Collections.Generic.Dictionary`2.FindValue(TKey key) at MsmhTools.HTTPProxyServer.TunnelManager.Remove(Int32 threadId) at MsmhTools.HTTPProxyServer.HTTPProxyServer.<>c__DisplayClass86_0.gdisposeIt|0() at MsmhTools.HTTPProxyServer.HTTPProxyServer.ConnectHttpsRequest(Int32 connectionId, TcpClient client, Request req, Boolean applyUpStreamProxy) at System.Threading.Tasks.Task.<>c.b128_1(Object state) at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() at System.Threading.Thread.StartCallback()

msasanmh commented 1 year ago

Recently I changed the behavior of the proxy from series to parallel but I forgot to use ConcurrentDictionary<TKey,TValue> and also it's better to lock the collection during the entire enumeration.

I'm gonna update the TunnelManager today or you can modify the code yourself.

Thanks for letting me know.

msasanmh commented 1 year ago

Fixed: v2.3.7 Code: TunnelManager It would be great if you could confirm.

Masoud-Kazemi commented 1 year ago

will do, i did not have the sdk and other apps ready where i am right now. also thanks for the quick fix. the code is alright , will respond after i got the release file.

Masoud-Kazemi commented 1 year ago

Up until now everything is working A OK. Hope i dont Jinx it. Until Next time, Have a Great Day !!