diff --git a/src/http.c b/src/http.c index 87e1ad2..b929e1c 100644 --- a/src/http.c +++ b/src/http.c @@ -85,7 +85,11 @@ static int wait_readable(j_conn *c, double idle_s, double deadline) int rc = poll(&p, 1, (int)(t * 1000.0) + 1); if (rc < 0) { if (errno == EINTR) continue; return -1; } if (rc == 0) { - if (g_progress && g_progress(c->role ? c->role : "upstream", t) != 0) return -1; + /* The progress hook writes a heartbeat to the client. If that write + * fails, the client is gone -- that is not an upstream fault and + * must not cool the endpoint. -2 says so; -1 stays "poll failed". */ + if (g_progress && g_progress(c->role ? c->role : "upstream", t) != 0) + return -2; continue; /* keep waiting until the deadline */ } return 1; @@ -114,6 +118,7 @@ ssize_t j_buf_read_until(j_conn *c, j_buf *b, const char *needle, size_t max, } if (b->len > max) { snprintf(err, errlen, "header_block_too_large"); return -1; } int w = wait_readable(c, idle_s, deadline); + if (w == -2) { snprintf(err, errlen, "client_gone"); return -1; } if (w < 0) { snprintf(err, errlen, "poll: %s", strerror(errno)); return -1; } if (w == 0) { snprintf(err, errlen, "timeout_waiting_headers"); return -2; } if (j_buf_reserve(b, b->len + J_READ_CHUNK + 1)) { snprintf(err, errlen, "oom"); return -1; } @@ -130,6 +135,7 @@ int j_buf_ensure(j_conn *c, j_buf *b, size_t from, size_t n, double idle_s, { while (b->len - from < n) { int w = wait_readable(c, idle_s, deadline); + if (w == -2) { snprintf(err, errlen, "client_gone"); return -1; } if (w < 0) { snprintf(err, errlen, "poll: %s", strerror(errno)); return -1; } if (w == 0) { snprintf(err, errlen, "timeout_waiting_body"); return -2; } if (j_buf_reserve(b, b->len + J_READ_CHUNK + 1)) { snprintf(err, errlen, "oom"); return -1; } diff --git a/src/junction.c b/src/junction.c index cf64144..7ebe738 100644 --- a/src/junction.c +++ b/src/junction.c @@ -4783,6 +4783,13 @@ static void handle_client_inner(j_conn *client) !strncmp(ep->base, "https://", 8), may_cache ? "miss" : "off"); goto done; } + /* + * The heartbeat to the client failed: the operator closed the stream. + * The endpoint did nothing wrong, so an abort must not cool it (one + * cancelled client used to cool the whole pool for the next request). + */ + if (rc == -1 && strcmp(err, "client_gone") == 0) + rc = -2; if (rc == -2) { ep->fail_count++;