Skip to content

fix: Remove regular expression match timeouts - #1820

Merged
HofmeisterAn merged 1 commit into
developfrom
fix/remove-regex-match-timeout
Nov 14, 2026
Merged

HofmeisterAn merged 1 commit into
developfrom
fix/remove-regex-match-timeout

Conversation

@HofmeisterAn

@HofmeisterAn HofmeisterAn commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Removes the match timeout from all regular expressions (23 call sites in the library, the test helpers, and the DocGen tool). The calls now use the Regex overloads without a timeout and fall back to the process-wide default (REGEX_DEFAULT_MATCH_TIMEOUT), which is infinite unless the application sets it.

The PR also disables the Sonar rule S6444 for the whole repository by adding it to NoWarn in Directory.Build.props. The timeouts were only added to satisfy this rule (#721). NoWarn is used instead of .editorconfig, because each module has its own .editorconfig with root = true.

Why is it important?

Users keep running into a RegexMatchTimeoutException when they create a builder, e.g. new PostgreSqlBuilder() fails in MatchImage.Match. The match takes microseconds, but the timeout measures wall-clock time. On busy CI agents, or when many tests start in parallel, the thread waits long enough for a CPU that the timeout expires. Increasing the limit from 1 to 5 seconds in 4.12 did not fix it, the issue still reproduces with 4.16.0.

The timeout protects web services against ReDoS, which does not apply to Testcontainers. Every input comes from the developer's own test code (image names, Dockerfiles, .dockerignore files, container logs), not from untrusted users.

This also affects UntilMessageIsLogged(string), which 30 modules use. Its 5 second timeout could fail the container start under load. The wait strategy timeout still limits how long the wait takes, and developers who want a timeout for their pattern can pass a Regex instance.

Related issues

Summary by CodeRabbit

  • Chores
    • Updated regular-expression matching to use the default timeout behavior across container configuration, image handling, and documentation generation.
    • Suppressed an additional analyzer warning.

@HofmeisterAn HofmeisterAn added bug Something isn't working enhancement New feature or request labels Nov 14, 2026
@netlify

netlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 7a754f7
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/6af8640bcaba3b09ee051fb8
😎 Deploy Preview https://deploy-preview-1820--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The changes remove explicit match timeouts from regex calls across container builders, image and Dockerfile processing, and documentation-generation tools. They also add S6444 to the NoWarn list.

Changes

Regex timeout changes

Layer / File(s) Summary
Container and builder regex calls
Directory.Build.props, src/Testcontainers.K3s/K3sContainer.cs, src/Testcontainers.Neo4j/Neo4jBuilder.cs, src/Testcontainers/Builders/*, src/Testcontainers/Configurations/WaitStrategies/UntilMessageIsLogged.cs
Regex calls in container and builder code no longer specify explicit match timeouts. S6444 was added to the warning suppression list.
Image and Dockerfile regex calls
src/Testcontainers/Images/*, tests/Testcontainers.Commons/DockerfileParser.cs
Regex calls for image matching, Dockerfile parsing, archive filenames, and ignore patterns no longer specify explicit match timeouts. The test parser pattern also uses the constructor without an explicit timeout.
Documentation generator regex calls
tools/Testcontainers.DocGen/*
Regex calls in the documentation generator no longer specify explicit match timeouts.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: george-petrakis

Merge Risk: Minimal · up to 7a754

This change removes regex match timeouts so that spurious RegexMatchTimeoutException failures no longer occur during builder creation and log waiting. The trade-off is that a pathological developer-supplied pattern is no longer bounded unless the developer passes a Regex with a timeout. No concrete merge-blocking risk was established.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix: Remove regular expression match timeouts" matches the main change. The PR removes explicit match timeouts from 23 regex call sites across the library, test helpers, and DocGen tool. Th…
Description check Passed The description covers the what, the why, and the related issues. It explains the removal of regex timeouts, the S6444 NoWarn change, and the reasons for both. It cites the linked issues #1629 and #15…
Linked Issues check Passed The only directly linked issue, #1629, is closed and completed. It supplies historical context only. No active directly linked issue remains, so no linked-issue coding requirements apply. The PR goal,…
Out of Scope Changes check Passed The changes in the whole-PR summary (merge base b349342 to head 7a754f7) all remove or adjust the explicit regex match timeouts. They touch 23 call sites in src/Testcontainers, src/Testcontainers.K3s,…
Full details: Title check

Explanation

The title "fix: Remove regular expression match timeouts" matches the main change. The PR removes explicit match timeouts from 23 regex call sites across the library, test helpers, and DocGen tool. The title is short and specific, and it uses a conventional commit prefix.

Full details: Description check

Explanation

The description covers the what, the why, and the related issues. It explains the removal of regex timeouts, the S6444 NoWarn change, and the reasons for both. It cites the linked issues #1629 and #1507. The "How to test this PR" section is still the unfilled template placeholder, and the description does not say how a reviewer should verify the change. The template also includes the placeholder comment block for related issues. Those are minor gaps.

Full details: Linked Issues check

Explanation

The only directly linked issue, #1629, is closed and completed. It supplies historical context only. No active directly linked issue remains, so no linked-issue coding requirements apply. The PR goal, removing the regex match timeouts that cause RegexMatchTimeoutException, relates to #1629 but is not a requirement from it. The PR references #1507 as related. That issue is not a directly linked target and is not assessed here.

Full details: Out of Scope Changes check

Explanation

The changes in the whole-PR summary (merge base b349342 to head 7a754f7) all remove or adjust the explicit regex match timeouts. They touch 23 call sites in src/Testcontainers, src/Testcontainers.K3s, src/Testcontainers.Neo4j, tests/Testcontainers.Commons, and tools/Testcontainers.DocGen. The Directory.Build.props change adds S6444 to NoWarn. The PR description states this suppression is needed because the timeouts were added only to satisfy that rule. The suppression is therefore connected to the stated purpose. It is repo-wide, which the reviewer may want to weigh, but it is not an unrelated change. The UntilMessageIsLogged change also removes the unused using System; directive. This is a minor cleanup tied to the edited file. No change is demonstrated to be unrelated to the PR purpose. This assessment relies on the summary. The per-file diffs were not inspected.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the regex trail,
While timeouts leave each call,
The patterns keep their shapes the same,
The warning list gains one name,
Then hops away beyond the wall.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1

src/Testcontainers/Configurations/WaitStrategies/UntilMessageIsLogged.cs-12-12: 1

12-12: Major · Stability & Availability · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Bound matching for string wait patterns.

If a caller supplies ^(a+)+$ and a log contains a long sequence of a followed by !, _pattern.IsMatch can spend an extremely long time backtracking. The wait deadline cannot interrupt that synchronous match, so it can continue consuming CPU after the deadline. Preserve a finite or configurable match bound for the string overload.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 631747b5-9031-45d6-ab89-be78aa59c15f
Commits

Reviewing files that changed from the base of the PR and between b349342 and 7a754f7.

Files selected for processing: 15

  • Directory.Build.props
  • src/Testcontainers.K3s/K3sContainer.cs
  • src/Testcontainers.Neo4j/Neo4jBuilder.cs
  • src/Testcontainers/Builders/BuildKitImageFromDockerfileBuilder.cs
  • src/Testcontainers/Builders/ComposeBuilder.cs
  • src/Testcontainers/Builders/ImageFromDockerfileBuilder.cs
  • src/Testcontainers/Configurations/WaitStrategies/UntilMessageIsLogged.cs
  • src/Testcontainers/Images/DockerImage.cs
  • src/Testcontainers/Images/DockerfileArchive.cs
  • src/Testcontainers/Images/IgnoreFile.cs
  • src/Testcontainers/Images/MatchImage.cs
  • tests/Testcontainers.Commons/DockerfileParser.cs
  • tools/Testcontainers.DocGen/BuilderDocumentation.cs
  • tools/Testcontainers.DocGen/MarkdownDocumentation.cs
  • tools/Testcontainers.DocGen/Program.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@HofmeisterAn
HofmeisterAn merged commit 479ce92 into develop Nov 14, 2026
157 of 164 checks passed
@HofmeisterAn
HofmeisterAn deleted the fix/remove-regex-match-timeout branch November 14, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Constant RegexMatchTimeoutException

1 participant