From a087266a278512d5017565e3beaccb895e58b6cc Mon Sep 17 00:00:00 2001 From: tony Date: Sun, 31 Mar 2024 23:58:17 -0700 Subject: [PATCH] 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 324b301d402c0e2330f33a7cd60e34e54336cef0 PiperOrigin-RevId: 620767619 --- src/csharp/Grpc.Tools/ProtoCompile.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/csharp/Grpc.Tools/ProtoCompile.cs b/src/csharp/Grpc.Tools/ProtoCompile.cs index ef199f6c981..8dd82b1cc44 100644 --- a/src/csharp/Grpc.Tools/ProtoCompile.cs +++ b/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 s_errorListFilters = new List() { @@ -591,12 +591,18 @@ namespace Grpc.Tools { 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."); } }