Mark proxy connection free on error

This commit is contained in:
2023-01-05 22:29:28 +01:00
parent c7be0adc66
commit 993cb65724
3 changed files with 6 additions and 3 deletions

View File

@ -90,6 +90,7 @@ static proxy_ctx_t *proxy_get_by_conf(host_config_t *conf) {
n++; n++;
} }
// TODO use semaphore to keep track of number of free proxy connections
try_again: try_again:
if (sem_wait(&lock) != 0) { if (sem_wait(&lock) != 0) {
if (errno == EINTR) { if (errno == EINTR) {

View File

@ -306,6 +306,7 @@ int main(int argc, char *const argv[]) {
notice("Ready to accept connections"); notice("Ready to accept connections");
// TODO handle timeouts in epoll
async_thread(); async_thread();
notice("Goodbye!"); notice("Goodbye!");

View File

@ -26,11 +26,14 @@ void proxy_handler_func(client_ctx_t *ctx) {
respond(ctx); respond(ctx);
if (ret == 1) { if (ret == 1) {
ctx->proxy->in_use = 0;
ctx->proxy = NULL;
} else if (ctx->use_proxy == 0) { } else if (ctx->use_proxy == 0) {
proxy_close(ctx->proxy); proxy_close(ctx->proxy);
} else if (ctx->use_proxy == 1) { } else if (ctx->use_proxy == 1) {
proxy_handler_2(ctx); proxy_handler_2(ctx);
ctx->proxy->in_use = 0;
ctx->proxy = NULL;
} else if (ctx->use_proxy == 2) { } else if (ctx->use_proxy == 2) {
// WebSocket // WebSocket
ws_handle_connection(ctx); 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 flags = (chunked ? PROXY_CHUNKED : 0) | (ctx->use_proxy & PROXY_COMPRESS);
int ret = proxy_send(ctx->proxy, &ctx->socket, len_to_send, flags); int ret = proxy_send(ctx->proxy, &ctx->socket, len_to_send, flags);
ctx->proxy->in_use = 0;
ctx->proxy = NULL;
if (ret < 0) { if (ret < 0) {
ctx->c_keep_alive = 0; ctx->c_keep_alive = 0;