reference Flags

--timeout

Accepted by
opengrep scan, opengrep ci, opengrep test
Value
SECONDS, a number
Default
5.0
Environment
OPENGREP_TIMEOUT
See also
--timeout-threshold, --interfile-timeout, --dynamic-timeout, --allow-rule-timeout-control, timeout, dynamic_timeout, --dynamic-timeout-max-multiplier, --dynamic-timeout-unit-kb, --jobs, --max-match-per-file, --max-memory, --optimizations, --time

Limits the time that a rule may spend on a file. The limit applies to each pair of a rule and a file separately. 0 removes the limit.

When a rule exceeds the limit on a file, Opengrep stops that rule on the file, drops its findings there, records a timeout error and continues with the other rules. The error is listed in the errors of the --json output, and a warning names the file and the rules. After --timeout-threshold rules have timed out on a file, Opengrep runs no further rules on it.

Other limits:

OPENGREP_TIMEOUT sets the value for opengrep scan and opengrep ci when the flag is not given.

Examples

A rule that runs out of time

slow.yaml
rules:  - id: slow    patterns:      - pattern: $F(..., $X, ...) + $G(..., $Y, ...)      - pattern-not: $F($X, $X, ...) + $G(...)    message: slow    languages: [python]    severity: INFO
Command and result
$ seq 20000 | sed 's/.*/x& = f(a, b, c) + g(d, e) + h(&)/' > big.py
$ opengrep scan --config slow.yaml --timeout 0.001 big.py 2>&1 | grep timeout
warning  1 timeout error(s) in big.py when running the following rules: [slow]