Skip to content

Commit 637ba48

Browse files
committed
fix(ingress): retry evidence without reloading haproxy
One APPLY_PENDING flag covered evidence, the combined PEMs and the haproxy reload, so evidence that kept failing redid all three on every retry pass -- a SIGUSR2 every few minutes, each leaving old workers holding connections for up to TIMEOUT_CLIENT (24h by default). Track the reload and the evidence separately and retry only the step that failed. Signed-off-by: Kevin Wang <wy721@qq.com>
1 parent 5d35c50 commit 637ba48

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

‎custom-domain/dstack-ingress/scripts/cert-lib.sh‎

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
# shellcheck disable=SC2034 # read by the mode scripts
1414
FIRST_PASS=true
1515

16-
# Set when certificates have been renewed but not yet applied to haproxy.
17-
# Survives across passes, so a failed apply is retried on the next one. Starts
18-
# set so every container start republishes the evidence: what a previous run
19-
# left in /evidences may list removed domains or an old account, or be half
20-
# published.
21-
APPLY_PENDING=true
16+
# Set when certificates have changed but haproxy, or the evidence, does not
17+
# show them yet. They survive across passes, so a failed step is retried on the
18+
# next one, and only that step: evidence that keeps failing must not reload
19+
# haproxy on every retry, as each reload leaves the old workers holding their
20+
# connections for up to TIMEOUT_CLIENT. Both start set so every container start
21+
# republishes the evidence: what a previous run left in /evidences may list
22+
# removed domains or an old account, or be half published.
23+
RELOAD_PENDING=true
24+
EVIDENCE_PENDING=true
2225

2326
build_combined_pems() {
2427
local domain fullchain privkey combined
@@ -84,29 +87,33 @@ run_pass() {
8487
done <<<"$(get-all-domains.sh)"
8588

8689
if [ "$changed" -eq 1 ]; then
87-
APPLY_PENDING=true
90+
RELOAD_PENDING=true
91+
EVIDENCE_PENDING=true
8892
fi
8993

9094
# Applying is separate from renewing, and retried until it sticks. A
9195
# renewal that reaches disk but not haproxy is invisible: the next pass
9296
# sees a fresh certificate, reports "nothing to renew", and never reloads
9397
# again -- so haproxy would serve the pre-renewal certificate until it
9498
# expires, which is soon, because being near expiry is why it renewed.
95-
if [ "$APPLY_PENDING" = true ]; then
96-
local applied=true
97-
collect_evidence || { echo "Evidence generation failed" >&2; applied=false; }
98-
build_combined_pems || { echo "Combined PEM build failed" >&2; applied=false; }
99-
haproxy_reload || applied=false
100-
if [ "$applied" = true ]; then
101-
APPLY_PENDING=false
99+
if [ "$EVIDENCE_PENDING" = true ]; then
100+
if collect_evidence; then
101+
EVIDENCE_PENDING=false
102102
else
103-
echo "[$(date)] Certificate apply incomplete; retrying on the next pass" >&2
103+
echo "[$(date)] Evidence generation failed; retrying on the next pass" >&2
104+
fi
105+
fi
106+
if [ "$RELOAD_PENDING" = true ]; then
107+
if build_combined_pems && haproxy_reload; then
108+
RELOAD_PENDING=false
109+
else
110+
echo "[$(date)] Certificate apply failed; retrying on the next pass" >&2
104111
fi
105112
fi
106113
FIRST_PASS=false
107114
[ "$failed" -eq 0 ] || return 1
108115
# Not a quiet pass either: wait the retry backoff, not RENEW_INTERVAL.
109-
[ "$APPLY_PENDING" = false ] || return 3
116+
[ "$RELOAD_PENDING" = false ] && [ "$EVIDENCE_PENDING" = false ] || return 3
110117
}
111118

112119
# $1: seconds to wait before the first pass, for a caller that has just run one.

0 commit comments

Comments
 (0)