C#: Grpc.Tools: Handle regex timeout when parsing protoc output (#36185)

Fix for https://github.com/grpc/grpc/issues/36162

Increase the regex timeout to 1 second. If a timeout occurs then log that the line could not be parsed.

Closes #36185

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36185 from tonydnewell:grpc.tools-regex-timeout 324b301d40
PiperOrigin-RevId: 620767619
pull/36207/head
tony 12 months ago committed by Copybara-Service
parent 03312884dc
commit a087266a27
  1. 8
      src/csharp/Grpc.Tools/ProtoCompile.cs

@ -126,7 +126,7 @@ namespace Grpc.Tools
"javanano", "js", "objc",
"php", "python", "ruby" };
static readonly TimeSpan s_regexTimeout = TimeSpan.FromMilliseconds(100);
static readonly TimeSpan s_regexTimeout = TimeSpan.FromSeconds(1);
static readonly List<ErrorListFilter> s_errorListFilters = new List<ErrorListFilter>()
{
@ -590,6 +590,8 @@ namespace Grpc.Tools
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
{
foreach (ErrorListFilter filter in s_errorListFilters)
{
try
{
Match match = filter.Pattern.Match(singleLine);
@ -598,6 +600,10 @@ namespace Grpc.Tools
filter.LogAction(Log, match);
return;
}
} catch (RegexMatchTimeoutException)
{
Log.LogWarning("Unable to parse output from protoc. Regex timeout.");
}
}
base.LogEventsFromTextOutput(singleLine, messageImportance);

Loading…
Cancel
Save