From 993cb65724379c553585ca46ea2614fd43bf9356 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 5 Jan 2023 22:29:28 +0100 Subject: [PATCH] Mark proxy connection free on error --- src/lib/proxy.c | 1 + src/server.c | 1 + src/worker/proxy_handler.c | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/proxy.c b/src/lib/proxy.c index 578963c..19e438c 100644 --- a/src/lib/proxy.c +++ b/src/lib/proxy.c @@ -90,6 +90,7 @@ static proxy_ctx_t *proxy_get_by_conf(host_config_t *conf) { n++; } + // TODO use semaphore to keep track of number of free proxy connections try_again: if (sem_wait(&lock) != 0) { if (errno == EINTR) { diff --git a/src/server.c b/src/server.c index db37ab7..7c1a2d5 100644 --- a/src/server.c +++ b/src/server.c @@ -306,6 +306,7 @@ int main(int argc, char *const argv[]) { notice("Ready to accept connections"); + // TODO handle timeouts in epoll async_thread(); notice("Goodbye!"); diff --git a/src/worker/proxy_handler.c b/src/worker/proxy_handler.c index 9dd9774..e50d4e5 100644 --- a/src/worker/proxy_handler.c +++ b/src/worker/proxy_handler.c @@ -26,11 +26,14 @@ void proxy_handler_func(client_ctx_t *ctx) { respond(ctx); if (ret == 1) { - + ctx->proxy->in_use = 0; + ctx->proxy = NULL; } else if (ctx->use_proxy == 0) { proxy_close(ctx->proxy); } else if (ctx->use_proxy == 1) { proxy_handler_2(ctx); + ctx->proxy->in_use = 0; + ctx->proxy = NULL; } else if (ctx->use_proxy == 2) { // WebSocket ws_handle_connection(ctx); @@ -137,8 +140,6 @@ static int proxy_handler_2(client_ctx_t *ctx) { int flags = (chunked ? PROXY_CHUNKED : 0) | (ctx->use_proxy & PROXY_COMPRESS); int ret = proxy_send(ctx->proxy, &ctx->socket, len_to_send, flags); - ctx->proxy->in_use = 0; - ctx->proxy = NULL; if (ret < 0) { ctx->c_keep_alive = 0;