diff --git a/src/lib/proxy.c b/src/lib/proxy.c index 30c4a72..b4a4b7b 100644 --- a/src/lib/proxy.c +++ b/src/lib/proxy.c @@ -399,8 +399,9 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu if (!retry) return -1; + // honor server timeout with one second buffer if (!proxy->initialized || sock_has_pending(&proxy->proxy, SOCK_DONTWAIT) != 0 || srv_error || - (proxy->http_timeout != 0 && (clock_micros() - proxy->proxy.ts_last) >= proxy->http_timeout)) + (proxy->http_timeout != 0 && (clock_micros() - proxy->proxy.ts_last_send) >= proxy->http_timeout - 1000000)) { if (proxy->initialized) proxy_close(proxy); diff --git a/src/lib/sock.c b/src/lib/sock.c index aef28a2..14c29c9 100644 --- a/src/lib/sock.c +++ b/src/lib/sock.c @@ -86,6 +86,7 @@ int sock_init(sock *s, int fd, int flags) { s->pipe = !!(flags & SOCK_PIPE); s->ts_start = clock_micros(); s->ts_last = s->ts_start; + s->ts_last_send = s->ts_last; s->timeout_us = -1; s->ssl = NULL; s->addr = NULL; @@ -224,6 +225,7 @@ long sock_send(sock *s, void *buf, unsigned long len, int flags) { if (ret >= 0) { s->ts_last = clock_micros(); + s->ts_last_send = s->ts_last; return ret; } else { return -1; diff --git a/src/lib/sock.h b/src/lib/sock.h index b90c47e..ecebcc2 100644 --- a/src/lib/sock.h +++ b/src/lib/sock.h @@ -31,7 +31,7 @@ typedef struct { char *addr, *s_addr; SSL_CTX *ctx; SSL *ssl; - long ts_start, ts_last, timeout_us; + long ts_start, ts_last, ts_last_send, timeout_us; } sock; void sock_error(sock *s, int ret); diff --git a/src/worker/tcp_acceptor.c b/src/worker/tcp_acceptor.c index 24794d1..24d4449 100644 --- a/src/worker/tcp_acceptor.c +++ b/src/worker/tcp_acceptor.c @@ -84,6 +84,7 @@ static int tcp_acceptor(client_ctx_t *ctx) { return -1; } client->ts_last = clock_micros(); + client->ts_last_send = client->ts_last; } ctx->req_num = 0;