From 511feb2e31e13758d7b0cae8715a15fef40477a5 Mon Sep 17 00:00:00 2001 From: HYec Date: Sat, 6 Jan 2018 22:06:15 +0800 Subject: [PATCH 1/2] Close sockets before stop plugins --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 89d4351c..f0df59bd 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -490,8 +490,6 @@ namespace Shadowsocks.Controller protected void Reload() { - StopPlugins(); - Encryption.RNG.Reload(); // some logic in configuration updated the config when saving, we need to read it again _config = Configuration.Load(); @@ -521,6 +519,10 @@ namespace Shadowsocks.Controller { _listener.Stop(); } + + // + StopPlugins(); + // don't put PrivoxyRunner.Start() before pacServer.Stop() // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1 // though UseShellExecute is set to true now @@ -554,7 +556,8 @@ namespace Shadowsocks.Controller if (e is SocketException) { SocketException se = (SocketException)e; - if (se.SocketErrorCode == SocketError.AccessDenied) + if (se.SocketErrorCode == SocketError.AccessDenied || + se.SocketErrorCode == SocketError.AddressAlreadyInUse) { e = new Exception(I18N.GetString("Port already in use"), e); } From 7564e79ede34fdf1773029c7879f75f7bde187fd Mon Sep 17 00:00:00 2001 From: HYec Date: Tue, 9 Jan 2018 23:08:50 +0800 Subject: [PATCH 2/2] Only start the current server's plugin --- .../Controller/ShadowsocksController.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index f0df59bd..7ae00824 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -520,7 +520,6 @@ namespace Shadowsocks.Controller _listener.Stop(); } - // StopPlugins(); // don't put PrivoxyRunner.Start() before pacServer.Stop() @@ -536,7 +535,7 @@ namespace Shadowsocks.Controller strategy.ReloadServers(); } - StartPlugins(); + StartPlugin(); privoxyRunner.Start(_config); TCPRelay tcpRelay = new TCPRelay(this, _config); @@ -556,8 +555,7 @@ namespace Shadowsocks.Controller if (e is SocketException) { SocketException se = (SocketException)e; - if (se.SocketErrorCode == SocketError.AccessDenied || - se.SocketErrorCode == SocketError.AddressAlreadyInUse) + if (se.SocketErrorCode == SocketError.AccessDenied) { e = new Exception(I18N.GetString("Port already in use"), e); } @@ -575,13 +573,10 @@ namespace Shadowsocks.Controller Utils.ReleaseMemory(true); } - private void StartPlugins() + private void StartPlugin() { - foreach (var server in _config.configs) - { - // Early start plugin processes - GetPluginLocalEndPointIfConfigured(server); - } + var server = _config.GetCurrentServer(); + GetPluginLocalEndPointIfConfigured(server); } protected void SaveConfig(Configuration newConfig)