diff options
author | pjd <pjd@FreeBSD.org> | 2011-04-02 09:31:02 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2011-04-02 09:31:02 +0000 |
commit | 6a5b53255825a135d8ea993273e737099ce88c63 (patch) | |
tree | 0fdb8b3fe612f21026b6f1f8fe217774b64e188e /sbin/hastd/proto_common.c | |
parent | ee9b74620b4b94a6bf4a1fe552711dc4e1622c8d (diff) | |
download | FreeBSD-src-6a5b53255825a135d8ea993273e737099ce88c63.zip FreeBSD-src-6a5b53255825a135d8ea993273e737099ce88c63.tar.gz |
Handle ENOBUFS on send(2) by retrying for a while and logging the problem.
MFC after: 1 week
Diffstat (limited to 'sbin/hastd/proto_common.c')
-rw-r--r-- | sbin/hastd/proto_common.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sbin/hastd/proto_common.c b/sbin/hastd/proto_common.c index 1d4c606..183b4e4 100644 --- a/sbin/hastd/proto_common.c +++ b/sbin/hastd/proto_common.c @@ -94,6 +94,7 @@ proto_common_send(int sock, const unsigned char *data, size_t size, int fd) { ssize_t done; size_t sendsize; + int errcount = 0; PJDLOG_ASSERT(sock >= 0); @@ -118,6 +119,23 @@ proto_common_send(int sock, const unsigned char *data, size_t size, int fd) } else if (done < 0) { if (errno == EINTR) continue; + if (errno == ENOBUFS) { + /* + * If there are no buffers we retry. + * After each try we increase delay before the + * next one and we give up after fifteen times. + * This gives 11s of total wait time. + */ + if (errcount == 15) { + pjdlog_warning("Getting ENOBUFS errors for 11s on send(), giving up."); + } else { + if (errcount == 0) + pjdlog_warning("Got ENOBUFS error on send(), retrying for a bit."); + errcount++; + usleep(100000 * errcount); + continue; + } + } /* * If this is blocking socket and we got EAGAIN, this * means the request timed out. Translate errno to @@ -131,6 +149,10 @@ proto_common_send(int sock, const unsigned char *data, size_t size, int fd) data += done; size -= done; } while (size > 0); + if (errcount > 0) { + pjdlog_info("Data sent successfully after %d ENOBUFS error%s.", + errcount, errcount == 1 ? "" : "s"); + } if (fd == -1) return (0); |