fix: prevent stale mutation execution
This commit is contained in:
@@ -11,6 +11,9 @@ if [[ -z "$bin_directory" && -r /etc/uce/settings.cfg ]]; then
|
||||
fi
|
||||
bin_directory="${bin_directory:-/tmp/uce/work}"
|
||||
cache_dir=""
|
||||
mutation_file="/tmp/uce-dependency-mutation-$$"
|
||||
post_body="/tmp/uce-dependency-post-body-$$"
|
||||
post_headers="/tmp/uce-dependency-post-headers-$$"
|
||||
http_host="${UCE_TEST_HTTP_HOST:-uce.openfu.com}"
|
||||
|
||||
cleanup() {
|
||||
@@ -18,6 +21,7 @@ cleanup() {
|
||||
if [[ -n "$cache_dir" ]]; then
|
||||
rm -rf "$cache_dir"
|
||||
fi
|
||||
rm -f "$mutation_file" "$post_body" "$post_headers"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
mkdir -p "$source_dir"
|
||||
@@ -31,7 +35,7 @@ printf '%s\n' \
|
||||
printf '%s\n' \
|
||||
'#load "child.uce"' \
|
||||
'CLI(Request& context) { print(dependency_cache_marker(), ":", request_perf()["worker_pid"].to_string()); }' \
|
||||
'RENDER(Request& context) { print(dependency_cache_marker(), ":", request_perf()["worker_pid"].to_string()); }' >"$source_dir/parent.uce"
|
||||
"RENDER(Request& context) { if(context.params[\"REQUEST_METHOD\"] == \"POST\") file_put_contents(\"$mutation_file\", dependency_cache_marker()); print(dependency_cache_marker(), \":\", request_perf()[\"worker_pid\"].to_string()); }" >"$source_dir/parent.uce"
|
||||
|
||||
assert_marker() {
|
||||
local path="$1"
|
||||
@@ -83,6 +87,15 @@ if (( elapsed_ms >= 2000 )); then
|
||||
echo "HTTP request spent ${elapsed_ms}ms rebuilding a stale artifact" >&2
|
||||
exit 1
|
||||
fi
|
||||
deadline=$((SECONDS + 15))
|
||||
while [[ "$http_during_rebuild" != *"dependency-marker-b"* && $SECONDS -lt $deadline ]]; do
|
||||
sleep 0.2
|
||||
http_during_rebuild=$(http_marker)
|
||||
done
|
||||
if [[ "$http_during_rebuild" != *"dependency-marker-b"* ]]; then
|
||||
echo "requested stale HTTP unit did not receive a demand-priority rebuild" >&2
|
||||
exit 1
|
||||
fi
|
||||
assert_marker parent dependency-marker-b
|
||||
|
||||
# A proactive rebuild owns these same per-unit locks. While it publishes fresh
|
||||
@@ -111,6 +124,26 @@ if (( elapsed_ms >= 2000 )); then
|
||||
echo "HTTP request waited ${elapsed_ms}ms for an active transitive rebuild" >&2
|
||||
exit 1
|
||||
fi
|
||||
rm -f "$mutation_file"
|
||||
started_at=$(date +%s%N)
|
||||
post_status=$(curl -sS -o "$post_body" -D "$post_headers" -w '%{http_code}' -X POST -H "Host: $http_host" "http://127.0.0.1/$test_name/parent.uce")
|
||||
elapsed_ms=$(( ($(date +%s%N) - started_at) / 1000000 ))
|
||||
if [[ "$post_status" != "503" ]]; then
|
||||
echo "stale POST executed an application artifact instead of returning 503: status=$post_status body=$(cat "$post_body")" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -qi '^Retry-After: 1' "$post_headers"; then
|
||||
echo "stale POST did not return a Retry-After header" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -e "$mutation_file" ]]; then
|
||||
echo "stale POST executed the old mutation handler: $(cat "$mutation_file")" >&2
|
||||
exit 1
|
||||
fi
|
||||
if (( elapsed_ms >= 2000 )); then
|
||||
echo "stale POST waited ${elapsed_ms}ms instead of failing closed promptly" >&2
|
||||
exit 1
|
||||
fi
|
||||
started_at=$(date +%s%N)
|
||||
assert_marker parent dependency-marker-d
|
||||
elapsed_ms=$(( ($(date +%s%N) - started_at) / 1000000 ))
|
||||
|
||||
Reference in New Issue
Block a user