Skip to content

Commit

Permalink
- Added CodeDomEvaluator.CscTimeout to allow auto-termination of th…
Browse files Browse the repository at this point in the history
…e `csc.exe` when it hangs. Triggered by oleg-shilo#318
  • Loading branch information
oleg-shilo committed Feb 25, 2023
1 parent a39fe31 commit a375579
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/CSScriptLib/src/CSScriptLib/Evaluator.CodeDom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ public class CodeDomEvaluator : EvaluatorBase<CodeDomEvaluator>, IEvaluator
/// </summary>
public static bool CompileOnServer = true;

/// <summary>
/// Timeout for the C# CLI compiler `csc.exe`.
/// <para>
/// This compiler is a part of .NET SDK and it is the actual
/// tool that compiles C# code into assembly when CodeDomEvaluator is used.
/// This tool under certain circumstances has tendency to hang after even if it successfully
/// finished the compilation. Thus configurable timeout allows user to configure forcible termination
/// of the csc.exe process.
/// </para>
/// <para>
/// The default value is -1 (infinite).</para>
/// </summary>
public static int CscTimeout = -1;

/// <summary>
/// The low level output of the last script compilation. This member is not designed to be a
/// part of script error handling. For this purpose a normal exception based mechanism the
Expand Down Expand Up @@ -302,7 +316,7 @@ bool buildServerNotRunning() => response.GetLines()
{
cmd = $@"""{Globals.csc}"" {common_args.JoinBy(" ")} /out:""{assembly}"" {refs_args.JoinBy(" ")} {source_args.JoinBy(" ")}";

result.NativeCompilerReturnValue = dotnet.Run(cmd, build_dir, x => result.Output.Add(x), x => std_err += x);
result.NativeCompilerReturnValue = dotnet.Run(cmd, build_dir, x => result.Output.Add(x), x => std_err += x, CodeDomEvaluator.CscTimeout);
}
}
else
Expand All @@ -311,7 +325,7 @@ bool buildServerNotRunning() => response.GetLines()

try
{
result.NativeCompilerReturnValue = Globals.csc.Run(cmd, build_dir, x => result.Output.Add(x), x => std_err += x);
result.NativeCompilerReturnValue = Globals.csc.Run(cmd, build_dir, x => result.Output.Add(x), x => std_err += x, CodeDomEvaluator.CscTimeout);
}
catch (Exception e)
{
Expand Down

0 comments on commit a375579

Please sign in to comment.