Skip to content

Commit

Permalink
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 authored and rgrinberg committed Dec 20, 2022
1 parent cd1ba37 commit 7bd5f34
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Fix binary corruption when installing or promoting in parallel (#6669, fixes
#6668, @edwintorok)

- Fix the parsing of alerts. They will now show up in diagnostics correctly.
(#6678, @rginberg)

Expand Down
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
10 changes: 5 additions & 5 deletions test/blackbox-tests/test-cases/version-corruption.t
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ shared buffer):
> EOF

$ rm -f gen_lifecycle.bc gen_lifecycle.exe && dune clean && dune build && ./gen_lifecycle.exe >/dev/null
Segmentation fault
[139]
$ cp _build/default/gen_lifecycle.exe gen_lifecycle.old

$ dune install -j16 --prefix=./_install 2>/dev/null
Expand All @@ -115,8 +113,10 @@ shared buffer):
- evaluates to: "v0.0.1"

$ ./compare.sh gen_lifecycle.old ./gen_lifecycle.exe
28362
100

$ ./gen_lifecycle.exe
Segmentation fault
[139]
0.0.1
0.0.1
0.0.1
0.0.1

0 comments on commit 7bd5f34

Please sign in to comment.