From e2f08fe36b9ecc46a2c1dd2d0c5ab07ffe16adfa Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 30 Apr 2015 09:14:12 +1000 Subject: [PATCH] Prevent sending parts of different messages to upstream proxies --- src/generator.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/generator.c b/src/generator.c index e7cf6f47..5b475e3d 100644 --- a/src/generator.c +++ b/src/generator.c @@ -115,6 +115,7 @@ struct proxy_instance { bool reconnecting; /* Testing of parent in progress */ int64_t recruit; /* No of recruiting requests in progress */ bool alive; + bool sending; /* Are we in the middle of a blocked write? */ pthread_t pth_precv; @@ -1533,10 +1534,17 @@ static void send_json_msgq(gdata_t *gdata, cs_msg_t **csmsgq) int ret; DL_FOREACH_SAFE(*csmsgq, csmsg, tmp) { + proxy_instance_t *proxy = csmsg->proxy; + + /* Only try to send one message at a time to each proxy + * to avoid sending parts of different messages */ + if (proxy->sending) + continue; while (csmsg->len) { - proxy_instance_t *proxy = csmsg->proxy; - int fd = proxy->cs.fd; + int fd; + proxy->sending = true; + fd = proxy->cs.fd; ret = send(fd, csmsg->buf + csmsg->ofs, csmsg->len, MSG_DONTWAIT); if (ret < 1) { if (errno == EAGAIN || errno == EWOULDBLOCK || !ret) @@ -1550,6 +1558,7 @@ static void send_json_msgq(gdata_t *gdata, cs_msg_t **csmsgq) csmsg->len -= ret; } if (!csmsg->len) { + proxy->sending = false; DL_DELETE(*csmsgq, csmsg); free(csmsg->buf); free(csmsg);