Commit Diff
Diff:
d28bd963c2450790bdb6bf2193af5670581c0c24
e0f6dc646d6c257869c17f16db977cd064262830
Commit:
e0f6dc646d6c257869c17f16db977cd064262830
Tree:
73a5052ca9af25d4416b13f1ced4a754ed958e63
Author:
Omar Polo <op@omarpolo.com>
Date:
Thu Jan 27 09:55:52 2022 UTC
Message:
improve proxy error path

properly release everything when during client_close if the request
was managed by a proxy.
commit - d28bd963c2450790bdb6bf2193af5670581c0c24
commit + e0f6dc646d6c257869c17f16db977cd064262830
blob - 9e8415dc232bc054d956e379bc1b53808ba25c9d
blob + 1dde21a616c047ea0605f1e9303d0df9417be29d
--- gmid.h
+++ gmid.h
@@ -240,6 +240,7 @@ struct client {
struct proxy *proxy;
struct bufferevent *proxybev;
struct tls *proxyctx;
+ int proxyevset;
struct event proxyev;
char *header;
blob - fa316748ccb8ca551beb05dce98826b09e20de36
blob + 97d32578cf96864ca118af922cfd31755de4ed64
--- proxy.c
+++ proxy.c
@@ -288,6 +288,7 @@ proxy_handshake(int fd, short event, void *d)
return;
}
+ c->proxyevset = 0;
proxy_enqueue_req(c);
}
@@ -327,6 +328,7 @@ proxy_setup_tls(struct client *c)
if (tls_connect_socket(c->proxyctx, c->pfd, p->host) == -1)
goto err;
+ c->proxyevset = 1;
event_set(&c->proxyev, c->pfd, EV_READ|EV_WRITE, proxy_handshake, c);
event_add(&c->proxyev, &handshake_timeout);
blob - e9211d318b874664db82204c238309592ff1f180
blob + c9cb7ce080393b7efdadc48b40a700167c767a7e
--- server.c
+++ server.c
@@ -1277,18 +1277,20 @@ client_close(struct client *c)
bufferevent_free(c->bev);
c->bev = NULL;
- if (c->proxybev != NULL) {
- if (event_pending(&c->proxyev, EV_READ|EV_WRITE, NULL))
- event_del(&c->proxyev);
-
- if (c->pfd != -1 && c->proxyctx != NULL) {
- /* shut down the proxy TLS connection */
- client_proxy_close(c->pfd, 0, c->proxyctx);
- c->pfd = -1;
- }
+ if (c->proxyevset &&
+ event_pending(&c->proxyev, EV_READ|EV_WRITE, NULL)) {
+ c->proxyevset = 0;
+ event_del(&c->proxyev);
+ }
- bufferevent_free(c->proxybev);
+ if (c->pfd != -1 && c->proxyctx != NULL) {
+ /* shut down the proxy TLS connection */
+ client_proxy_close(c->pfd, 0, c->proxyctx);
+ c->pfd = -1;
}
+
+ if (c->proxybev != NULL)
+ bufferevent_free(c->proxybev);
client_close_ev(c->fd, 0, c);
}
Omar Polo