From 92ad3c76cdd324e3723cf1a05e4873fc0bfd0234 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Wed, 13 Jan 2016 15:24:20 +1100 Subject: [PATCH] Don't try to passthrough_send messages to dead proxies or sockets --- src/generator.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/generator.c b/src/generator.c index e55500ab..f789446d 100644 --- a/src/generator.c +++ b/src/generator.c @@ -1717,19 +1717,25 @@ static void *proxy_send(void *arg) static void passthrough_send(ckpool_t *ckp, pass_msg_t *pm) { + proxy_instance_t *proxy = pm->proxy; connsock_t *cs = pm->cs; int len, sent; + if (unlikely(!proxy->alive || cs->fd < 0)) { + LOGDEBUG("Dropping send to dead proxy of upstream json msg: %s", pm->msg); + goto out; + } LOGDEBUG("Sending upstream json msg: %s", pm->msg); len = strlen(pm->msg); sent = write_socket(cs->fd, pm->msg, len); - if (unlikely(sent != len && cs->fd)) { + if (unlikely(sent != len)) { LOGWARNING("Failed to passthrough %d bytes of message %s, attempting reconnect", len, pm->msg); Close(cs->fd); - pm->proxy->alive = false; + proxy->alive = false; reconnect_generator(ckp); } +out: free(pm->msg); free(pm); }