reference Rule options

timeout

Value
seconds, a number
See also
--timeout, dynamic_timeout

With --allow-rule-timeout-control, timeout replaces --timeout for this rule: the rule may spend that many seconds on each file, whether that is more or less than the limit of the scan. Without the flag, the option is ignored.

--timeout 0 removes every time limit, and the option then has no effect.

With dynamic_timeout, the value is the base that the size of the file multiplies.

Examples

A rule's own limit, allowed or not

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

Without the flag, slow gets the 5 seconds of the scan and finishes. With the flag, its own limit of a millisecond applies. patient finishes although the limit of the scan is a millisecond, because its own limit is 100 seconds.