Handle foreign-owned compile artifacts
This commit is contained in:
@@ -55,6 +55,12 @@ COMPILE_FAILURE_RETRY_SECONDS=60
|
||||
CFG
|
||||
mount --bind "$settings" /etc/uce/settings.cfg
|
||||
|
||||
mkdir -p "$root/compiler/src/wasm" "$root/compiler/scripts"
|
||||
cp -a src/lib "$root/compiler/src/lib"
|
||||
cp -a src/wasm/abi.h "$root/compiler/src/wasm/abi.h"
|
||||
cp -a scripts/compile_wasm_unit scripts/build_unit_source_map.py scripts/check_unit_wasm.py "$root/compiler/scripts/"
|
||||
chmod -R a+rX "$root/compiler"
|
||||
|
||||
cat >"$root/compile" <<SHIM
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
@@ -66,6 +72,13 @@ if [[ -r '$root/stage-timeout' ]] && grep -Fxq "\$source_file" '$root/stage-time
|
||||
cp "\$2/\$(basename "\$source_file").wasm.source-map" "\$2/\$5.source-map"
|
||||
sleep 60
|
||||
fi
|
||||
if [[ -r '$root/copy-delay' ]] && grep -Fxq "\$source_file" '$root/copy-delay'; then
|
||||
cp "\$2/\$(basename "\$source_file").wasm" "\$2/\$5"
|
||||
cp "\$2/\$(basename "\$source_file").wasm.source-map" "\$2/\$5.source-map"
|
||||
sleep 1.5
|
||||
touch '$root/copy-delay-complete'
|
||||
exit 0
|
||||
fi
|
||||
if [[ -r '$root/hold' ]] && grep -Fxq "\$source_file" '$root/hold'; then
|
||||
printf '%s\n' "\$\$" >'$root/compiler-pid'
|
||||
(sleep 3; touch '$root/late-descendant') &
|
||||
@@ -74,7 +87,7 @@ fi
|
||||
if [[ -r '$root/silent-fail' ]] && grep -Fxq "\$source_file" '$root/silent-fail'; then exit 23; fi
|
||||
if [[ -r '$root/empty-success' ]] && grep -Fxq "\$source_file" '$root/empty-success'; then exit 0; fi
|
||||
if [[ -r '$root/delay' ]] && grep -Fxq "\$source_file" '$root/delay'; then sleep 1; fi
|
||||
exec '$(pwd)/scripts/compile_wasm_unit' "\$@"
|
||||
exec '$root/compiler/scripts/compile_wasm_unit' "\$@"
|
||||
SHIM
|
||||
chmod +x "$root/compile"
|
||||
|
||||
@@ -97,9 +110,19 @@ printf '%s\n' 'COMPONENT(Request& context) { print("component"); }' >"$site/comp
|
||||
timeout 40s env UCE_PRECOMPILE_FILES_IN="$site" UCE_PRECOMPILE_BIN_DIRECTORY="$work" UCE_PRECOMPILE_JOBS=1 bin/uce_fastcgi.linux.bin --precompile >"$root/precompile.log" 2>&1 || { cat "$root/precompile.log" >&2; exit 1; }
|
||||
cache="$(scripts/unit_cache_directory "$work")$(realpath "$site")"
|
||||
generation=$(scripts/unit_cache_directory "$work")
|
||||
service_user=${UCE_TEST_SERVICE_USER:-www-data}
|
||||
service_uid=$(id -u "$service_user")
|
||||
service_gid=$(id -g "$service_user")
|
||||
generation_before=$(<"$generation/source-generation.txt")
|
||||
[[ $(sysctl -n fs.protected_hardlinks) == 1 ]]
|
||||
[[ $(stat -c %u "$cache/slow.uce.wasm") == 0 && $(stat -c %u "$generation/source-generation.txt") == 0 ]]
|
||||
[[ $(stat -c %u "$cache/slow.uce.wasm.lock") == 0 && $(stat -c %u "$generation/source-generation.txt.lock") == 0 ]]
|
||||
find "$work" -type d -exec chown "$service_uid:$service_gid" {} +
|
||||
chown -R "$service_uid:$service_gid" "$root/run" "$root/session" "$root/upload"
|
||||
chown "$service_uid:$service_gid" "$root"
|
||||
rm -f "$cache/cold-entry.uce."* "$cache/components/slow-component.uce."*
|
||||
|
||||
timeout --signal=TERM --kill-after=5s 90s bin/uce_fastcgi.linux.bin >"$log" 2>&1 &
|
||||
timeout --signal=TERM --kill-after=5s 90s setpriv --reuid="$service_uid" --regid="$service_gid" --clear-groups bin/uce_fastcgi.linux.bin >"$log" 2>&1 &
|
||||
server_pid=$!
|
||||
for _ in $(seq 1 400); do [[ -S "$root/run/cli.sock" ]] && break; sleep 0.02; done
|
||||
[[ -S "$root/run/cli.sock" ]] || { cat "$log" >&2; exit 1; }
|
||||
@@ -127,8 +150,29 @@ done
|
||||
worker_pid=${driver%%|*}
|
||||
[[ "$driver" == "$worker_pid|health" ]]
|
||||
[[ "$(request /driver.uce)" == compiled ]]
|
||||
[[ $(stat -c %u "$cache/slow.uce.wasm") == "$service_uid" ]]
|
||||
[[ $(stat -c %u "$generation/source-generation.txt") == "$service_uid" ]]
|
||||
[[ $(<"$generation/source-generation.txt") != "$generation_before" ]]
|
||||
! grep -q 'Could not write.*source-generation.txt' "$log"
|
||||
before=$(sha256sum "$cache/slow.uce.wasm" "$cache/slow.uce.wasm.source-map" "$cache/slow.uce.cpp" "$cache/slow.uce.exports.txt" "$cache/slow.uce.meta.txt")
|
||||
|
||||
truncate -s 1073741824 "$cache/slow.uce.cwasm"
|
||||
printf '%s\n' "$site/slow.uce" >"$root/copy-delay"
|
||||
rm -f "$root/copy-delay-complete"
|
||||
started=$(date +%s%N)
|
||||
set +e
|
||||
copy_timeout=$(request /driver.uce 2>&1)
|
||||
set -e
|
||||
elapsed=$(( ($(date +%s%N) - started) / 1000000 ))
|
||||
rm -f "$root/copy-delay"
|
||||
[[ "$copy_timeout" == *UCE_INVOCATION_TIMEOUT:* ]] || { echo "foreign rollback copy lacked timeout: $copy_timeout" >&2; exit 1; }
|
||||
(( elapsed >= 1700 && elapsed <= 3500 )) || { echo "foreign rollback copy took ${elapsed}ms" >&2; exit 1; }
|
||||
[[ -e "$root/copy-delay-complete" ]] || { echo "foreign rollback compiler did not finish before timeout" >&2; exit 1; }
|
||||
[[ $(stat -c '%u:%s' "$cache/slow.uce.cwasm") == '0:1073741824' ]]
|
||||
[[ "$before" == "$(sha256sum "$cache/slow.uce.wasm" "$cache/slow.uce.wasm.source-map" "$cache/slow.uce.cpp" "$cache/slow.uce.exports.txt" "$cache/slow.uce.meta.txt")" ]]
|
||||
! find "$cache" -name '*.invocation-*' -print -quit | grep -q .
|
||||
rm -f "$cache/slow.uce.cwasm"
|
||||
|
||||
assert_timeout() {
|
||||
local url="$1" source="$2" started elapsed output
|
||||
printf '%s\n' "$source" >"$root/hold"
|
||||
@@ -203,4 +247,4 @@ elapsed=$(( ($(date +%s%N) - started) / 1000000 ))
|
||||
flock -u 9
|
||||
[[ "$locked" == *UCE_INVOCATION_TIMEOUT:* && "$elapsed" -le 3500 ]]
|
||||
|
||||
echo "wasm compile timeout passed (entry, explicit, dynamic, unit/registry locks, error page, process group, staging, native precompile)"
|
||||
echo "wasm compile timeout passed (entry, explicit, dynamic, unit/registry locks, error page, process group, staging, native precompile, foreign-owned artifacts)"
|
||||
|
||||
Reference in New Issue
Block a user