Infrequent printing concurrency bug

Open
#133 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@maciejpirog is already working on this.

Since Aug 12, 2025.

Assessment

This issue has not been assessed yet.

Description

bug ocaml-5

Describe the bug

Printing is not thread-safe. Relevant once #123 is merged.

To Reproduce

# run this command in a loop until error with some rule, in the opengrep repo: 
#
# opengrep-cli --experimental --timeout 5 --max-memory 5000 -j 8 -c <some-rule>.yaml  src/ libs/ 

$ n=0; while time opengrep-cli scan --experimental --timeout 5 --max-memory 5000 -j 8 -c <some-rule>.yaml src/ libs/ 2> >(tee /dev/stderr | grep -q "ERROR" && exit 1); do ((n++)); done; echo "failed after $((n+1)) attempts"

[01.62][ERROR]: Error: exception Invalid_argument: String.sub / Bytes.sub
Raised at Stdlib.invalid_arg in file "stdlib.ml", line 30, characters 20-45
Called from Stdlib__String.sub in file "string.ml" (inlined), line 43, characters 2-23
Called from Str.string_after in file "str.ml" (inlined), line 24, characters 23-59
Called from Matches_report.cut in file "src/osemgrep/reporting/Matches_report.ml", line 176, characters 4-27
Called from Matches_report.pp_finding.(fun) in file "src/osemgrep/reporting/Matches_report.ml", line 244, characters 25-55
Called from Stdlib__List.fold_left in file "list.ml", line 123, characters 24-34
Called from Matches_report.pp_finding in file "src/osemgrep/reporting/Matches_report.ml", lines 198-250, characters 4-28
Called from Matches_report.pp_text_outputs.print_one_match in file "src/osemgrep/reporting/Matches_report.ml", lines 379-381, characters 4-13
Called from List_.iter_with_view_into_neighbor_elements.loop in file "libs/commons/List_.ml", line 134, characters 8-28
Called from Stdlib__List.iter in file "list.ml", line 112, characters 12-15
Called from Output.output_result in file "src/osemgrep/reporting/Output.ml", line 253, characters 2-71
Called from Scan_subcommand.check_targets_with_rules in file "src/osemgrep/cli_scan/Scan_subcommand.ml", lines 660-663, characters 12-41
Called from Scan_subcommand.run_scan_conf in file "src/osemgrep/cli_scan/Scan_subcommand.ml", lines 805-813, characters 8-61
Called from CLI.dispatch_subcommand in file "src/osemgrep/cli/CLI.ml", line 196, characters 20-57
Called from CLI.safe_run in file "src/osemgrep/cli/CLI.ml", line 228, characters 8-12

opengrep-cli --experimental --timeout 5 --max-memory 5000 -j 8 -c ... src/ libs/  5.03s user 1.28s system 382% cpu 1.650 total
failed after 5101 attempts

What is the priority of the bug to you?

  • P0: blocking your adoption of Opengrep or workflow
  • P1: important to fix or quite annoying
  • P2: regular bug that should get fixed
Dominant language
OCaml
Stars
3.2k
Forks
272
Avg merge
1d 14h
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opengrep/opengrep

All issues in opengrep/opengrep

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.