From 506721435def1c6f340fc8262f950a34121a1fa5 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Fri, 21 Nov 2014 22:41:49 +0800 Subject: [PATCH 1/5] fix a crash --- shadowsocks-csharp/Controller/PACServer.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index 7b39252d..6e611b2b 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -174,7 +174,12 @@ Connection: Close private void SendCallback(IAsyncResult ar) { Socket conn = (Socket)ar.AsyncState; - conn.Shutdown(SocketShutdown.Send); + try + { + conn.Shutdown(SocketShutdown.Send); + } + catch + { } } private void WatchPacFile() From e13d2287aaf978395c46c1bb07849408b9a05be6 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Sun, 23 Nov 2014 01:01:41 +0800 Subject: [PATCH 2/5] just log useful exceptions --- shadowsocks-csharp/Controller/Local.cs | 26 +++++++++++++------------- shadowsocks-csharp/Controller/Logging.cs | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/shadowsocks-csharp/Controller/Local.cs b/shadowsocks-csharp/Controller/Local.cs index 97f21474..15649b40 100755 --- a/shadowsocks-csharp/Controller/Local.cs +++ b/shadowsocks-csharp/Controller/Local.cs @@ -144,7 +144,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -176,7 +176,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); } } if (remote != null) @@ -188,7 +188,7 @@ namespace Shadowsocks.Controller } catch (SocketException e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); } } lock (encryptionLock) @@ -218,7 +218,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -236,7 +236,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -269,7 +269,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -296,7 +296,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -324,7 +324,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -346,7 +346,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -384,7 +384,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -421,7 +421,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -440,7 +440,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } @@ -459,7 +459,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { - Console.WriteLine(e); + Logging.LogUsefulException(e); this.Close(); } } diff --git a/shadowsocks-csharp/Controller/Logging.cs b/shadowsocks-csharp/Controller/Logging.cs index 58a994f5..ada32ce5 100755 --- a/shadowsocks-csharp/Controller/Logging.cs +++ b/shadowsocks-csharp/Controller/Logging.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net.Sockets; using System.Text; namespace Shadowsocks.Controller @@ -30,5 +31,31 @@ namespace Shadowsocks.Controller return false; } } + + public static void LogUsefulException(Exception e) + { + // just log useful exceptions, not all of them + if (e is SocketException) + { + SocketException se = (SocketException)e; + if (se.SocketErrorCode == SocketError.ConnectionAborted) + { + // closed by browser when sending + // normally happens when download is canceled or a tab is closed before page is loaded + } + else if (se.SocketErrorCode == SocketError.ConnectionReset) + { + // received rst + } + else + { + Console.WriteLine(e); + } + } + else + { + Console.WriteLine(e); + } + } } } From 3b5c09907d95e031adc09d07460a7352a3f2b6d1 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Sun, 23 Nov 2014 01:08:09 +0800 Subject: [PATCH 3/5] only switch the system proxy off if we have switched it on --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index b4de4cf9..f5bdb44c 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -22,6 +22,8 @@ namespace Shadowsocks.Controller private PolipoRunner polipoRunner; private bool stopped = false; + private bool _systemProxyIsDirty = false; + public class PathEventArgs : EventArgs { public string Path; @@ -174,10 +176,16 @@ namespace Shadowsocks.Controller if (_config.enabled) { SystemProxy.Enable(); + _systemProxyIsDirty = true; } else { - SystemProxy.Disable(); + // only switch it off if we have switched it on + if (_systemProxyIsDirty) + { + SystemProxy.Disable(); + _systemProxyIsDirty = false; + } } } From a8f2435c89cb3a9c0c1b596f102e6c1b0e386695 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Sun, 23 Nov 2014 01:09:11 +0800 Subject: [PATCH 4/5] bump --- shadowsocks-csharp/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Properties/AssemblyInfo.cs b/shadowsocks-csharp/Properties/AssemblyInfo.cs index e65ce0b3..47f94a5e 100755 --- a/shadowsocks-csharp/Properties/AssemblyInfo.cs +++ b/shadowsocks-csharp/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.10")] +[assembly: AssemblyVersion("2.0.11")] // [assembly: AssemblyFileVersion("2.0.0")] From 58e0bdba28c379c497127984c723ccfaccdcb552 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Sun, 23 Nov 2014 01:10:34 +0800 Subject: [PATCH 5/5] update changes --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index 4c57bf68..b84ed21e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +2.0.11 2014-11-23 +- Fix a crash +- Only switch the system proxy off if we have switched it on + 2.0.10 2014-11-18 - Minor fixes - Optimize code