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 when trying to parse HTTP version #1159

Closed
APErebus opened this issue Aug 22, 2024 · 2 comments
Closed

RegexMatchTimeoutException when trying to parse HTTP version #1159

APErebus opened this issue Aug 22, 2024 · 2 comments
Assignees
Labels

Comments

@APErebus
Copy link

Describe the bug

In our automated testing, we are seeing intermittent failures due to the HttpVersionParse.Parse() throwing a RegexMatchTimeoutException.

{
   "ClassName":"System.Text.RegularExpressions.RegexMatchTimeoutException",
   "Message":"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.",

   "Data":null,
   "InnerException":null,
   "HelpURL":null,
   "StackTraceString":"
      at System.Text.RegularExpressions.RegexRunner.g__ThrowRegexTimeout|25_0()
         at Regex354_TryMatchAtCurrentPosition(RegexRunner, ReadOnlySpan`1)
         at Regex354_Scan(RegexRunner, ReadOnlySpan`1)
         at System.Text.RegularExpressions.Regex.RunSingleMatch(RegexRunnerMode mode, Int32 prevlen, String input, Int32 beginning, Int32 length, Int32 startat)
         at System.Text.RegularExpressions.Regex.Match(String input)
         at WireMock.Util.HttpVersionParser.Parse(String protocol)
         at WireMock.Owin.Mappers.OwinRequestMapper.MapAsync(HttpRequest request, IWireMockMiddlewareOptions options)
         at WireMock.Owin.WireMockMiddleware.InvokeInternalAsync(HttpContext ctx)
         at WireMock.Owin.GlobalExceptionMiddleware.InvokeInternalAsync(HttpContext ctx)",
   "RemoteStackTraceString":null,
   "RemoteStackIndex":0,
   "ExceptionMethod":null,
   "HResult":-2146233083,
   "Source":"System.Text.RegularExpressions",
   "WatsonBuckets":null,
   "regexInput":"HTTP/1.1",
   "regexPattern":"HTTP/(\\d+(\\.\\d+)?(?!\\.))",
   "timeoutTicks":1000000
}

Expected behavior:

We expect the regex to parse all the time with no exceptions

Test to reproduce

We don't have reliable reproduceable test scenarios as it's intermittent. 1-2 failures every 1000 runs.

Other related info

Our suspicion is that the 100ms timeout is too short and test systems under load might not be able to parse fast enough, throwing the exception.

Can we make this default value higher (500ms) or make it configurable so we can set it to a higher value?

@APErebus APErebus added the bug label Aug 22, 2024
@StefH StefH self-assigned this Aug 22, 2024
@StefH
Copy link
Collaborator

StefH commented Aug 22, 2024

Thanks for noticing.

I did add a timeout to most Regex to be compliant with SonarCloud warnings.

I'll need to check all Regex and probably will take a higher value, 10 seconds.

@StefH
Copy link
Collaborator

StefH commented Aug 22, 2024

#1160

@StefH StefH closed this as completed Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants