Skip to content

Commit

Permalink
Merge pull request #4712 from hxdhttk/hxdhttk/statePortConf
Browse files Browse the repository at this point in the history
Fix the state ports conflicts when multiple `v2rayN` instances start in a short period.
  • Loading branch information
2dust committed Feb 13, 2024
2 parents c03c981 + 74149b7 commit 9b3ac15
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions v2rayN/v2rayN/Handler/LazyConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@ public sealed class LazyConfig

public static LazyConfig Instance => _instance.Value;

private int _statePort;
public int StatePort { get => _statePort; }
private Job _processJob = new();
private int? _statePort;
public int StatePort
{
get
{
if (_statePort is null)
{
_statePort = Utils.GetFreePort();
}

return _statePort.Value;
}
}

private Job _processJob = new();

public LazyConfig()
{
_statePort = Utils.GetFreePort();

SqliteHelper.Instance.CreateTable<SubItem>();
SqliteHelper.Instance.CreateTable<ProfileItem>();
SqliteHelper.Instance.CreateTable<ServerStatItem>();
Expand Down Expand Up @@ -68,7 +78,7 @@ public int GetLocalPort(string protocol)
}
return localPort;
}

public void AddProcess(IntPtr processHandle)
{
_processJob.AddProcess(processHandle);
Expand Down

0 comments on commit 9b3ac15

Please sign in to comment.