Browse Source

Merge pull request #1336 from rwasef1830/use_job_for_sip003_plugin

Use job objects with SIP003 plugin to avoid lingering processes if app is killed
tags/4.0.6
Allen Zhu GitHub 7 years ago
parent
commit
b0a2c2735b
2 changed files with 27 additions and 3 deletions
  1. +6
    -0
      shadowsocks-csharp/Controller/Service/Sip003Plugin.cs
  2. +21
    -3
      shadowsocks-csharp/Controller/ShadowsocksController.cs

+ 6
- 0
shadowsocks-csharp/Controller/Service/Sip003Plugin.cs View File

@@ -5,6 +5,7 @@ using System.Net;
using System.Net.Sockets;
using System.Reflection;
using Shadowsocks.Model;
using Shadowsocks.Util.ProcessManagement;

namespace Shadowsocks.Controller.Service
{
@@ -15,6 +16,7 @@ namespace Shadowsocks.Controller.Service
public int ProcessId => _started ? _pluginProcess.Id : 0;

private readonly object _startProcessLock = new object();
private readonly Job _pluginJob;
private readonly Process _pluginProcess;
private bool _started;
private bool _disposed;
@@ -66,6 +68,8 @@ namespace Shadowsocks.Controller.Service
}
}
};

_pluginJob = new Job();
}

public bool StartIfNeeded()
@@ -88,6 +92,7 @@ namespace Shadowsocks.Controller.Service
_pluginProcess.StartInfo.Environment["SS_LOCAL_HOST"] = LocalEndPoint.Address.ToString();
_pluginProcess.StartInfo.Environment["SS_LOCAL_PORT"] = LocalEndPoint.Port.ToString();
_pluginProcess.Start();
_pluginJob.AddProcess(_pluginProcess.Handle);
_started = true;
}

@@ -124,6 +129,7 @@ namespace Shadowsocks.Controller.Service
try
{
_pluginProcess.Dispose();
_pluginJob.Dispose();
}
catch (Exception) { }



+ 21
- 3
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -158,10 +158,18 @@ namespace Shadowsocks.Controller
return null;
}
if (plugin.StartIfNeeded())
try
{
if (plugin.StartIfNeeded())
{
Logging.Info(
$"Started SIP003 plugin for {server.Identifier()} on {plugin.LocalEndPoint} - PID: {plugin.ProcessId}");
}
}
catch (Exception ex)
{
Logging.Info(
$"Started SIP003 plugin for {server.Identifier()} on {plugin.LocalEndPoint} - PID: {plugin.ProcessId}");
Logging.Error("Failed to start SIP003 plugin: " + ex.Message);
throw;
}
return plugin.LocalEndPoint;
@@ -526,6 +534,7 @@ namespace Shadowsocks.Controller
strategy.ReloadServers();
}
StartPlugins();
privoxyRunner.Start(_config);
TCPRelay tcpRelay = new TCPRelay(this, _config);
@@ -563,6 +572,15 @@ namespace Shadowsocks.Controller
Utils.ReleaseMemory(true);
}
private void StartPlugins()
{
foreach (var server in _config.configs)
{
// Early start plugin processes
GetPluginLocalEndPointIfConfigured(server);
}
}
protected void SaveConfig(Configuration newConfig)
{
Configuration.Save(newConfig);


Loading…
Cancel
Save