diff --git a/src/junction.c b/src/junction.c index 0c802f0..6d84dce 100644 --- a/src/junction.c +++ b/src/junction.c @@ -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);