Skip Menu |
 

From: Arlene Berry <aberry@likewise.com>
To: "krb5-bugs@mit.edu" <krb5-bugs@mit.edu>
Subject: blocking recv caused our server to hang
Date: Thu, 21 Jul 2011 22:19:08 +0000
Download (untitled) / with headers
text/plain 1.5KiB
We've had this patch in our local source for a long time and the original description says select reported a socket as ready for reading but the recv blocked which caused our server to hang. This was seen on multiple versions of Solaris and possibly elsewhere. We solved it by changing all sockets to non-blocking.

Index: src/lib/krb5/os/sendto_kdc.c
===================================================================
--- src/lib/krb5/os/sendto_kdc.c (revision 25023)
+++ src/lib/krb5/os/sendto_kdc.c (working copy)
@@ -758,6 +758,8 @@
{
int fd, e;
unsigned int ssflags;
+ static const int one = 1;
+ static const struct linger lopt = { 0, 0 };

dprint("start_connection(@%p)\ngetting %s socket in family %d...", state,
state->socktype == SOCK_STREAM ? "stream" : "dgram", state->family);
@@ -769,14 +771,11 @@
}
set_cloexec_fd(fd);
/* Make it non-blocking. */
+ if (ioctlsocket(fd, FIONBIO, (const void *) &one))
+ dperror("sendto_kdc: ioctl(FIONBIO)");
+ if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &lopt, sizeof(lopt)))
+ dperror("sendto_kdc: setsockopt(SO_LINGER)");
if (state->socktype == SOCK_STREAM) {
- static const int one = 1;
- static const struct linger lopt = { 0, 0 };
-
- if (ioctlsocket(fd, FIONBIO, (const void *) &one))
- dperror("sendto_kdc: ioctl(FIONBIO)");
- if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &lopt, sizeof(lopt)))
- dperror("sendto_kdc: setsockopt(SO_LINGER)");
TRACE_SENDTO_KDC_TCP_CONNECT(context, state);
}
From: ghudson@mit.edu
Subject: SVN Commit

In rare circumstances, such as checksum errors, some network stacks
can flag an fd for reading in select() and still block when the fd is
read. Set all sockets non-blocking to prevent hangs when this occurs.
(We don't actually handle the resulting EWOULDBLOCK or EAGAIN errors,
so the rare cases will appear as communication failures and we will
close the socket. This is already the case for TCP sockets and
probably isn't a big deal.)


https://github.com/krb5/krb5/commit/d47cb3023828da211cd342f6d94d56c97d102227
Commit By: ghudson
Revision: 25048
Changed Files:
U trunk/src/lib/krb5/os/sendto_kdc.c