From ceb6814332ae032e8abc120dfff2480179660aa0 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 13 Mar 2020 08:35:09 -0400 Subject: [PATCH] TT#76368 handle connection blocking on graphite writes Change-Id: I261bb890fa7f403061f92c1300b69a3833282f09 --- daemon/graphite.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/daemon/graphite.c b/daemon/graphite.c index 402a7aa06..47fb6e316 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -233,11 +233,27 @@ static int send_graphite_data(struct totalstats *sent_data) { (unsigned long long)ts->delete.time_max.tv_sec,(unsigned long long)ts->delete.time_max.tv_usec, (unsigned long long)ts->delete.time_avg.tv_sec,(unsigned long long)ts->delete.time_avg.tv_usec); - int rc = write(graphite_sock.fd, graph_str->str, graph_str->len); - if (rc<0) { - ilog(LOG_ERROR,"Could not write to graphite socket. Disconnecting graphite server."); - goto error; + size_t sent = 0; + int blockings = 10; // let it block that many times + while (sent < graph_str->len) { + int rc = write(graphite_sock.fd, graph_str->str + sent, graph_str->len - sent); + if (rc<0) { + if (blockings <= 0 || (errno != EWOULDBLOCK && errno != EAGAIN && errno != EINTR)) { + ilog(LOG_ERROR,"Could not write to graphite socket (%s). " \ + "Disconnecting graphite server.", strerror(errno)); + goto error; + } + rc = 0; + } + if (rc == 0) { + // poor man's blocking handling + blockings--; + usleep(500000); + continue; + } + sent += rc; } + g_string_free(graph_str, TRUE); return 0;