diff --git a/src/lib/proxy.c b/src/lib/proxy.c index 1429e57..cba4c14 100644 --- a/src/lib/proxy.c +++ b/src/lib/proxy.c @@ -307,11 +307,9 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu goto proxy; retry: - if (proxy->initialized) { - info(BLUE_STR "Closing proxy connection"); - sock_close(&proxy->proxy); - proxy->initialized = 0; - } + if (proxy->initialized) + proxy_close(proxy); + retry = 0; tries++; @@ -323,7 +321,7 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu return -1; } - if (sock_set_timeout(&proxy->proxy, SERVER_TIMEOUT_INIT) != 0) + if (sock_set_socket_timeout(&proxy->proxy, 1) != 0 || sock_set_timeout(&proxy->proxy, SERVER_TIMEOUT_INIT) != 0) goto proxy_timeout_err; struct hostent *host_ent = gethostbyname2(conf->proxy.hostname, AF_INET6); @@ -383,6 +381,7 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu ret = SSL_do_handshake(proxy->proxy.ssl); if (ret != 1) { error_ssl(SSL_get_error(proxy->proxy.ssl, (int) ret)); + SSL_free(proxy->proxy.ssl); res->status = http_get_status(502); ctx->origin = SERVER_REQ; error("Unable to perform handshake"); diff --git a/src/server.c b/src/server.c index 23ef0b4..992415a 100644 --- a/src/server.c +++ b/src/server.c @@ -202,7 +202,7 @@ static void terminate_gracefully(int sig) { workers_destroy(); while (list_size(clients) > 0) - server_free_client(clients[0]); + tcp_close(clients[0]); proxy_close_all(); logger_set_prefix("");