Skip to content

Commit 7bd5f34

Browse files
edwintorokrgrinberg
authored andcommitted
fix: binary corruption during parallel promotion/install
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 <edvin.torok@citrix.com>
1 parent cd1ba37 commit 7bd5f34

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Unreleased
22
----------
33

4+
- Fix binary corruption when installing or promoting in parallel (#6669, fixes
5+
#6668, @edwintorok)
6+
47
- Fix the parsing of alerts. They will now show up in diagnostics correctly.
58
(#6678, @rginberg)
69

src/dune_rules/artifact_substitution.ml

+1-2
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ end
415415

416416
let buf_len = max_len
417417

418-
let buf = Bytes.create buf_len
419-
420418
type mode =
421419
| Test
422420
| Copy of
@@ -469,6 +467,7 @@ output the replacement | |
469467
v} *)
470468
let parse ~input ~mode =
471469
let open Fiber.O in
470+
let buf = Bytes.create buf_len in
472471
let rec loop scanner_state ~beginning_of_data ~pos ~end_of_data ~status =
473472
let scanner_state = Scanner.run scanner_state ~buf ~pos ~end_of_data in
474473
let placeholder_start =

test/blackbox-tests/test-cases/version-corruption.t

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ shared buffer):
9595
> EOF
9696

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

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

117115
$ ./compare.sh gen_lifecycle.old ./gen_lifecycle.exe
118-
28362
116+
100
119117

120118
$ ./gen_lifecycle.exe
121-
Segmentation fault
122-
[139]
119+
0.0.1
120+
0.0.1
121+
0.0.1
122+
0.0.1

0 commit comments

Comments
 (0)