Skip to content

Commit c69c0c8

Browse files
committed
Fix hang when using --exec flag in Nix sandboxed builds
The busy-wait loop at await.c:900-906 was spinning at 100% CPU without yielding, preventing the exec thread from completing in constrained environments like Nix's sandboxed builds. Added msleep(10) to the loop to allow the exec thread to get CPU time. This fixes 4 tests that were timing out in Nix builds: - test_placeholder_in_exec - test_exec_runs_on_success - test_exec_with_fail_flag - test_exec_with_output All 46 tests now pass in nix-build. Also added default.nix and shell.nix for Nix package maintainers. Fixes #18
1 parent 353a59a commit c69c0c8

4 files changed

Lines changed: 87 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# await
2-
40K, small memory footprint, single binary that run list of commands in parallel and waits for their termination
2+
36K build/await, small memory footprint, single binary that run list of commands in parallel and waits for their termination
33

44
<!-- DO NOT CHANGE THIS FILE IS GENERATED BY ./hooks/pre-commit -->
55

await.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ int main(int argc, char *argv[]) {
903903
fprintf(stderr, "\033[%dB\r", args.nCommands + 1);
904904
return 0;
905905
}
906+
msleep(10); // Sleep 10ms to allow exec thread to run
906907
}
907908
}
908909
}

default.nix

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
3+
pkgs.stdenv.mkDerivation {
4+
pname = "await";
5+
version = "2.1.0";
6+
7+
src = ./.;
8+
9+
nativeBuildInputs = with pkgs; [
10+
cmake
11+
];
12+
13+
nativeCheckInputs = with pkgs; [
14+
python312
15+
python312Packages.pytest
16+
];
17+
18+
doCheck = true;
19+
20+
preCheck = ''
21+
# TMPDIR is already set by Nix to a writable sandbox location
22+
# Just replace the await path for tests
23+
substituteInPlace ../tests/test_await.py \
24+
--replace-fail "../await" "../build/await"
25+
'';
26+
27+
checkPhase = ''
28+
runHook preCheck
29+
30+
# Return to source directory since build happens in ./build
31+
cd ..
32+
cd tests
33+
python -m pytest test_await.py -v
34+
35+
runHook postCheck
36+
'';
37+
38+
installPhase = ''
39+
# After tests we're in tests/, go back to source root
40+
cd ..
41+
42+
mkdir -p $out/bin
43+
cp build/await $out/bin/
44+
45+
mkdir -p $out/share/bash-completion/completions
46+
cp build/await.bash $out/share/bash-completion/completions/await
47+
48+
mkdir -p $out/share/fish/vendor_completions.d
49+
cp build/await.fish $out/share/fish/vendor_completions.d/
50+
51+
mkdir -p $out/share/zsh/site-functions
52+
cp build/await.zsh $out/share/zsh/site-functions/_await
53+
'';
54+
55+
meta = with pkgs.lib; {
56+
description = "Runs list of commands and waits for their termination";
57+
homepage = "https://github.com/slavaGanzin/await";
58+
license = licenses.mit;
59+
platforms = platforms.unix;
60+
};
61+
}

shell.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
3+
pkgs.mkShell {
4+
buildInputs = with pkgs; [
5+
cmake
6+
gcc
7+
python312
8+
python312Packages.pytest
9+
bash
10+
];
11+
12+
shellHook = ''
13+
echo "Nix development environment for await"
14+
echo "Building with CMake..."
15+
16+
# Set up similar to Nix build environment
17+
export TMPDIR="''${TMPDIR:-/tmp}"
18+
export HOME="''${HOME:-/build}"
19+
20+
echo "TMPDIR: $TMPDIR"
21+
echo "Run 'mkdir build && cd build && cmake .. && make' to build"
22+
echo "Run 'cd tests && pytest test_await.py -v' to run tests"
23+
'';
24+
}

0 commit comments

Comments
 (0)