[krbdev.mit.edu #6933] blocking recv caused our server to hang

Arlene Berry via RT rt-comment at krbdev.mit.edu
Fri Jul 22 15:38:01 EDT 2011


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);
     }






More information about the krb5-bugs mailing list