Skip to content

Commit

Permalink
Merge pull request #4711 from hxdhttk/hxdhttk/mixedStdErr
Browse files Browse the repository at this point in the history
Fix misleading "Cannot mix synchronous and asynchronous operation on process stream." logs.
  • Loading branch information
2dust committed Feb 13, 2024
2 parents af3c1dc + 44cfa2d commit c03c981
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions v2rayN/v2rayN/Handler/CoreHandler.cs
Expand Up @@ -156,7 +156,7 @@ public void CoreStopPid(int pid)

#region Private

private string CoreFindexe(CoreInfo coreInfo)
private string CoreFindExe(CoreInfo coreInfo)
{
string fileName = string.Empty;
foreach (string name in coreInfo.coreExes)
Expand Down Expand Up @@ -266,7 +266,7 @@ private void ShowMsg(bool updateToTrayTooltip, string msg)
{
try
{
string fileName = CoreFindexe(coreInfo);
string fileName = CoreFindExe(coreInfo);
if (Utils.IsNullOrEmpty(fileName))
{
return null;
Expand All @@ -286,6 +286,8 @@ private void ShowMsg(bool updateToTrayTooltip, string msg)
StandardErrorEncoding = displayLog ? Encoding.UTF8 : null,
}
};
var startUpErrorMessage = new StringBuilder();
var startUpSuccessful = false;
if (displayLog)
{
proc.OutputDataReceived += (sender, e) =>
Expand All @@ -302,6 +304,11 @@ private void ShowMsg(bool updateToTrayTooltip, string msg)
{
string msg = e.Data + Environment.NewLine;
update(false, msg);
if (!startUpSuccessful)
{
startUpErrorMessage.Append(msg);
}
}
};
}
Expand All @@ -314,7 +321,12 @@ private void ShowMsg(bool updateToTrayTooltip, string msg)

if (proc.WaitForExit(1000))
{
throw new Exception(displayLog ? proc.StandardError.ReadToEnd() : "启动进程失败并退出 (Failed to start the process and exited)");
proc.CancelErrorRead();
throw new Exception(displayLog ? startUpErrorMessage.ToString() : "启动进程失败并退出 (Failed to start the process and exited)");
}
else
{
startUpSuccessful = true;
}

LazyConfig.Instance.AddProcess(proc.Handle);
Expand Down

0 comments on commit c03c981

Please sign in to comment.