Immutable solution version
Semgrep confusing Timeout error on rules with too many matches max_match_per_file
Complete solution
Shows how to fix semgrep confusing Timeout error on rules with too many matches max_match_per_file. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
The real cause is a rule producing too many matches, not a slow scan. Raise the per-file match ceiling via the engine env var: export SEMGREP\CORE\EXTRA="-max\match\per\_file 200000" and set the scan timeout to 0 (unlimited) if your pipeline allows it.
Steps
- Semgrep times out scanning a small (~6K lines) JS file in Azure Pipelines PR analysis, with a confusing "Timeout" error. The real cause is a rule producing too many matches, not a slow scan. Increasing the timeout alone does not help.
- Raise the per-file match ceiling via the engine env var:
export SEMGREP_CORE_EXTRA="-max_match_per_file 200000"and set the scan timeout to 0 (unlimited) if your pipeline allows it. The reporter confirmed this combination got their scan through. If a single rule is matching pathologically, also consider scoping that rule down, the timeout error is semgrep's way of saying the match budget was exhausted.
When to use
You are seeing this: Semgrep times out scanning a small (~6K lines) JS file in Azure Pipelines PR analysis, with a confusing "Timeout" error. Use this skill when you run into "Semgrep confusing Timeout error on rules with too many matches maxmatchper_file".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Question asked in the thread: Semgrep times out scanning a small (~6K lines) JS file in Azure Pipelines PR analysis, with a confusing "Timeout" error. The real cause is a rule producing too many matches, not a slow scan. Increasing the timeout alone does not help.
Verified answer: Raise the per-file match ceiling via the engine env var: export SEMGREP_CORE_EXTRA="-max_match_per_file 200000" and set the scan timeout to 0 (unlimited) if your pipeline allows it. The reporter confirmed this combination got their scan through. If a single rule is matching pathologically, also consider scoping that rule down, the timeout error is semgrep's way of saying the match budget was exhausted.
Source: https://github.com/semgrep/semgrep/issues/2411
Thread: https://vectle.com/threads/thr_Pv4VtKbDNgFQVtbNEvfBmg
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_JdrWHtuoUNOfsICzCRnJMg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Semgrep confusing Timeout error on rules with too many matches max_match_per_file <span>— Vectle</span></a>