From owner-freebsd-bugs@freebsd.org Fri Sep 16 00:39:57 2016 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D34EFBDCBCE for ; Fri, 16 Sep 2016 00:39:57 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C30BF6C0 for ; Fri, 16 Sep 2016 00:39:57 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id u8G0dvCx097619 for ; Fri, 16 Sep 2016 00:39:57 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 212716] recv() with MSG_WAITALL doesn't always unblock on EOF Date: Fri, 16 Sep 2016 00:39:57 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 10.3-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: lew@perftech.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Sep 2016 00:39:57 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D212716 Bug ID: 212716 Summary: recv() with MSG_WAITALL doesn't always unblock on EOF Product: Base System Version: 10.3-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Many People Priority: --- Component: kern Assignee: freebsd-bugs@FreeBSD.org Reporter: lew@perftech.com We have a simple test program to illustrate the problem. Run "server" on a machine, and then run "client" on the same machine. Server creates a listening socket and loops accepting connections, sending a little data, closing the socket, and then back to the top of the loop. Client creates a socket, connects to the server, does a recv() with MSG_WAITALL, closes the socket, and loops. This runs anywhere from one to a few dozen times and then hangs. The server socket is in FIN_WAIT_2, and the client socket is in CLOSE_WAIT. So the cl= ient side is waiting for the application to close the socket, but it's still stu= ck in the recv(), never being awakened by the EOF from the server closing the socket. The same code runs on Linux and QNX without any problem. This seems ridiculously simple and far reaching. Seems like we must be overlooking something, but it's a really simple test case. client.c: #include #include #include #include #include #include #include #include #include #include int main (int argc, char *argv[]) { int c; bool verbose =3D false; char *addr =3D "127.0.0.1"; signal(SIGPIPE, SIG_IGN); while ((c =3D getopt(argc, argv, "v")) !=3D -1) { switch (c) { case 'v': ++verbose; break; default: return 1; break; } } argc -=3D optind - 1; argv +=3D optind - 1; if (argc > 1) addr =3D argv[1]; for (int try =3D 1;; try++) { printf("Try %d\n", try); int s; if ((s =3D socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) err(1, "socket"); struct sockaddr_in sa =3D { .sin_family =3D AF_INET, .sin_port =3D ht= ons(79), .sin_addr.s_addr =3D inet_addr(addr) }; if (connect(s, (struct sockaddr *)&sa, sizeof sa) < 0) err(1, "connect"); // get the response char rbuf [4096]; int rcvLen; if ((rcvLen =3D recv(s, rbuf, sizeof rbuf, MSG_WAITALL)) < 0) err(1, "recv"); if (verbose) printf("Received: '%.*s'\n", rcvLen, rbuf); close(s); } return 0; } server.c: #include #include #include #include #include #include #include #include #include #include #include int main (int argc, char *argv[]) { int c; bool verbose =3D false; signal(SIGPIPE, SIG_IGN); while ((c =3D getopt(argc, argv, "v")) !=3D -1) { switch (c) { case 'v': ++verbose; break; default: return 1; break; } } argc -=3D optind - 1; argv +=3D optind - 1; int s0; if ((s0 =3D socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) err(1, "socket"); int on =3D true; if (setsockopt(s0, SOL_SOCKET, SO_REUSEPORT, &on, sizeof on) < 0) err(1, "setsockopt"); struct sockaddr_in sa =3D { .sin_family =3D AF_INET, .sin_port =3D htons= (79) }; if (bind(s0, (struct sockaddr *)&sa, sizeof sa) < 0) err(1, "bind"); if (listen(s0, 1000) < 0) err(1, "listen"); printf("Listening\n"); for (int try =3D 1;; try++) { socklen_t sl; int s =3D accept(s0, (struct sockaddr *)&sa, &sl); if (s < 0) err(1, "accept"); printf("Try %d\n", try); // send the response static char sbuf [] =3D "Hello from server\n"; if (send(s, sbuf, sizeof sbuf - 1, 0) < 0) err(1, "send"); if (verbose) printf("Sent: %s", sbuf); shutdown(s, SHUT_WR); close(s); } return 0; } --=20 You are receiving this mail because: You are the assignee for the bug.=