My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Batch sudo calls in Stack.merge — one sudo per container, not per layer

Stack.merge was spawning a separate sudo cp process per dep layer,
causing hundreds of zombie sudo processes per container build. Now
batches all cp commands into a single sudo bash -c call.

Also includes the earlier fiber explosion fix for the DAG executor.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+29 -27
+29 -27
day11/layer/stack.ml
··· 2 2 module Log = (val Logs.src_log src_log) 3 3 4 4 let merge env ~layer_dirs ~target = 5 - let rec loop = function 6 - | [] -> Ok () 7 - | layer_dir :: rest -> 8 - let fs = Fpath.(layer_dir / "fs") in 9 - if not (Bos.OS.Dir.exists fs |> Result.get_ok) then begin 10 - Log.debug (fun m -> 11 - m "Skipping %a (no fs/ subdir)" Fpath.pp layer_dir); 12 - loop rest 13 - end else begin 14 - let result = 15 - Day11_exec.Sudo.run env 16 - Bos.Cmd.(v "cp" 17 - % "-n" 18 - % "--archive" 19 - % "--no-dereference" 20 - % "--recursive" 21 - % "--link" 22 - % "--no-target-directory" 23 - % Fpath.to_string fs 24 - % Fpath.to_string target) 25 - in 26 - match result with 27 - | Ok _ -> loop rest 28 - | Error _ as e -> e 29 - end 30 - in 31 - loop layer_dirs 5 + (* Collect all layer fs/ dirs that exist *) 6 + let fs_dirs = List.filter_map (fun layer_dir -> 7 + let fs = Fpath.(layer_dir / "fs") in 8 + if Bos.OS.Dir.exists fs |> Result.get_ok then 9 + Some (Fpath.to_string fs) 10 + else begin 11 + Log.debug (fun m -> 12 + m "Skipping %a (no fs/ subdir)" Fpath.pp layer_dir); 13 + None 14 + end 15 + ) layer_dirs in 16 + if fs_dirs = [] then Ok () 17 + else begin 18 + (* Batch all cp commands into a single sudo call to avoid 19 + spawning hundreds of sudo processes for large dep lists *) 20 + let target_s = Fpath.to_string target in 21 + let cmds = List.map (fun fs -> 22 + Printf.sprintf "cp -n --archive --no-dereference --recursive --link --no-target-directory %s %s" 23 + (Filename.quote fs) (Filename.quote target_s) 24 + ) fs_dirs in 25 + let script = String.concat " && " cmds in 26 + let result = 27 + Day11_exec.Sudo.run env 28 + Bos.Cmd.(v "bash" % "-c" % script) 29 + in 30 + match result with 31 + | Ok _ -> Ok () 32 + | Error _ as e -> e 33 + end