cooldown: Retry-After des Anbieters nach erschöpften Versuchen merken
Ein 429 mit "Retry-After: 86400" wurde nur für den einen Request beachtet; danach lief die nächste Anfrage wieder in dasselbe erschöpfte Kontingent. Jetzt wird der Endpunkt nach dem letzten fehlgeschlagenen Versuch bis zum genannten Zeitpunkt gesperrt und die Sperre beim späteren Fehler-Eintrag nicht mehr durch die kürzere eigene cooldown-Zeit überschrieben. Leere Abbrüche bekommen einen Namen: client_write_failed, wenn die Antwort schon beim Schreiben an den Client scheitert, client_stream_failed beim Weiterleiten des Rumpfs. Vorher stand im Log nur "aborted ... error=".
This commit is contained in:
1 parent
da3b46d5a7
commit
29aa281ca9
1 file changed
+15
-1
+15
-1
@@ -2858,6 +2858,7 @@ static int forward_step(j_conn *client, j_endpoint *ep, const j_req *rq,
|
||||
sse_error(client, r.status, msg);
|
||||
}
|
||||
t_heartbeat = NULL;
|
||||
if (!err[0]) snprintf(err, errlen, "client_stream_failed");
|
||||
resp_free(&r);
|
||||
j_conn_close(&up);
|
||||
free(body_alloc);
|
||||
@@ -3018,6 +3019,7 @@ static int forward_step(j_conn *client, j_endpoint *ep, const j_req *rq,
|
||||
send_head(client, r.status, r.reason, &r.hdrs, r.chunked ? -2 : r.content_length,
|
||||
err, errlen)) {
|
||||
t_heartbeat = NULL;
|
||||
if (!err[0]) snprintf(err, errlen, "client_write_failed");
|
||||
resp_free(&r);
|
||||
j_conn_close(&up);
|
||||
free(body_alloc);
|
||||
@@ -3103,6 +3105,17 @@ static int forward_with_retry(j_conn *client, j_endpoint *ep, const j_req *rq,
|
||||
if (rc == 0 || rc == -2) return rc;
|
||||
if (!err_retryable(err)) return rc;
|
||||
}
|
||||
/* The provider named a reset time and all retries failed. Bench the endpoint
|
||||
* until then for the following requests too; the per-request retry above is
|
||||
* already over. */
|
||||
if (rc != 0 && rc != -2 && !head_sent && t_retry_after_s > 0) {
|
||||
STATE_LOCK();
|
||||
double until = now_s() + (double)t_retry_after_s;
|
||||
if (until > ep->cooldown_until) ep->cooldown_until = until;
|
||||
STATE_UNLOCK();
|
||||
jlog("cooldown", "endpoint=%s reason=retry_after reset_s=%d",
|
||||
ep->name, t_retry_after_s);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3834,7 +3847,8 @@ static void handle_client(j_conn *client)
|
||||
ep->name, CFG.offline_hold_s, err);
|
||||
strncat(attempts, " offline", sizeof attempts - strlen(attempts) - 1);
|
||||
} else {
|
||||
ep->cooldown_until = now_s() + ep->cooldown_s;
|
||||
double cool_until = now_s() + ep->cooldown_s;
|
||||
if (cool_until > ep->cooldown_until) ep->cooldown_until = cool_until;
|
||||
STATE_UNLOCK();
|
||||
jlog("failed", "endpoint=%s error=%s", ep->name, err);
|
||||
strncat(attempts, " failed", sizeof attempts - strlen(attempts) - 1);
|
||||
|
||||
Reference in new issue
Block a user