Skip to content

Commit

Permalink
C#: Grpc.Tools: Handle regex timeout when parsing protoc output (#36185)
Browse files Browse the repository at this point in the history
Fix for #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=#36185 from tonydnewell:grpc.tools-regex-timeout 324b301
PiperOrigin-RevId: 620767619
  • Loading branch information
tonydnewell authored and Copybara-Service committed Apr 1, 2024
1 parent 0331288 commit a087266
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/csharp/Grpc.Tools/ProtoCompile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public class ProtoCompile : ToolTask
"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>()
{
Expand Down Expand Up @@ -591,12 +591,18 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport
{
foreach (ErrorListFilter filter in s_errorListFilters)
{
Match match = filter.Pattern.Match(singleLine);
try
{
Match match = filter.Pattern.Match(singleLine);

if (match.Success)
if (match.Success)
{
filter.LogAction(Log, match);
return;
}
} catch (RegexMatchTimeoutException)
{
filter.LogAction(Log, match);
return;
Log.LogWarning("Unable to parse output from protoc. Regex timeout.");
}
}

Expand Down

0 comments on commit a087266

Please sign in to comment.