Correctly reset msg_controllen before processing TCP error queue. (#26250)

When we call recvmsg(), we are allowed to set msg_control and
msg_controllen to receive ancillary messages from the TCP socket.
msg_controllen is set to available buffer length for such sockets
before we call recvmsg(); after the call returns successfully, it
contains the amount of available data in the ancillary buffer.

Existing behaviour is buggy; it calls recvmsg() in a loop but does not
set msg_controllen to the size of the full buffer correctly on each
iteration. This leads to a surfeit of error log messages, claiming the
ancillary messages had to be truncated due to insufficient buffer
space.

This patch correctly sets the ancillary buffer size before each call
to recvmsg() when processing the TCP error queue.
reviewable/pr26134/r1
Arjun Roy 4 years ago committed by GitHub
parent f36a31b6aa
commit cc9326c936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/lib/iomgr/tcp_posix.cc

@ -1164,9 +1164,9 @@ static bool process_errors(grpc_tcp* tcp) {
struct cmsghdr align; struct cmsghdr align;
} aligned_buf; } aligned_buf;
msg.msg_control = aligned_buf.rbuf; msg.msg_control = aligned_buf.rbuf;
msg.msg_controllen = sizeof(aligned_buf.rbuf);
int r, saved_errno; int r, saved_errno;
while (true) { while (true) {
msg.msg_controllen = sizeof(aligned_buf.rbuf);
do { do {
r = recvmsg(tcp->fd, &msg, MSG_ERRQUEUE); r = recvmsg(tcp->fd, &msg, MSG_ERRQUEUE);
saved_errno = errno; saved_errno = errno;

Loading…
Cancel
Save