Skip to content

Commit

Permalink
dune: fix binary corruption during parallel promotion/install
Browse files Browse the repository at this point in the history
Fixes ocaml#6668

When performing multiple promotions in parallel (e.g. for a .bc and an .exe)
then sharing a single global buf means that one of them could get corrupted
if the buffer is overwritten by the other build.

Do not use global variables: allocate a new per-file buffer in 'parse' instead!

`cd test && dune build @unit-tests/artifact_substitution/runtest @blackbox-tests/test-cases/versioncorruption` passes now

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed Dec 12, 2022
1 parent f26f1c0 commit 48cc447
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/dune_rules/artifact_substitution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,6 @@ end

let buf_len = max_len

let buf = Bytes.create buf_len

type mode =
| Test
| Copy of
Expand Down Expand Up @@ -469,6 +467,7 @@ output the replacement | |
v} *)
let parse ~input ~mode =
let open Fiber.O in
let buf = Bytes.create buf_len in
let rec loop scanner_state ~beginning_of_data ~pos ~end_of_data ~status =
let scanner_state = Scanner.run scanner_state ~buf ~pos ~end_of_data in
let placeholder_start =
Expand Down

0 comments on commit 48cc447

Please sign in to comment.