Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegexMatchTimeoutException in Grpc.Tools.ProtoCompile.Execute when building proto files in csproj #36162

Open
kikcorp opened this issue Mar 21, 2024 · 2 comments

Comments

@kikcorp
Copy link

kikcorp commented Mar 21, 2024

Dear team, do you have if there are any ways to set a timeout or avoid this error during the building process?

In source code i can't see anything

https://github.com/grpc/grpc/blob/master/src/csharp/Grpc.Tools/ProtoCompile.cs#L129

/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: The "ProtoCompile" task failed unexpectedly.
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: System.Text.RegularExpressions.RegexMatchTimeoutException: The Regex engine has timed out while trying to match a pattern to an input string. This can occur for many reasons, including very large inputs or excessive backtracking caused by nested quantifiers, back-references and other factors.
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at System.Text.RegularExpressions.RegexRunner.g__ThrowRegexTimeout|25_0()
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Regex8_TryMatchAtCurrentPosition(RegexRunner, ReadOnlySpan1) /root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Regex8_Scan(RegexRunner, ReadOnlySpan1)
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at System.Text.RegularExpressions.Regex.RunSingleMatch(RegexRunnerMode mode, Int32 prevlen, String input, Int32 beginning, Int32 length, Int32 startat)
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at System.Text.RegularExpressions.Regex.Match(String input)
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Grpc.Tools.ProtoCompile.LogEventsFromTextOutput(String singleLine, MessageImportance messageImportance) in /var/local/git/grpc/src/csharp/Grpc.Tools/ProtoCompile.cs:line 594
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.LogMessagesFromStandardErrorOrOutput(Queue dataQueue, ManualResetEvent dataAvailableSignal, MessageImportance messageImportance, StandardOutputOrErrorQueueType queueType)
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.HandleToolNotifications(Process proc)
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.Execute()
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Grpc.Tools.ProtoCompile.Execute() in /var/local/git/grpc/src/csharp/Grpc.Tools/ProtoCompile.cs:line 611
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
/root/.nuget/packages/grpc.tools/2.59.0/build/_protobuf/Google.Protobuf.Tools.targets(291,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

@jzabroski
Copy link

The compiler uses regular expressions?

@tonydnewell
Copy link
Contributor

There is no way to set the regex timeout. It is hard coded to 100 ms.

static readonly TimeSpan s_regexTimeout = TimeSpan.FromMilliseconds(100);

Regular expressions are used to parse error messages returned by the protoc compiler.

Is there a particular .proto file that is causing you problems?

copybara-service bot pushed a commit that referenced this issue Apr 1, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants