From owner-freebsd-bugs@FreeBSD.ORG Thu May 25 17:40:38 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2349516A4A1 for ; Thu, 25 May 2006 17:40:38 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id CD44243D73 for ; Thu, 25 May 2006 17:40:18 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k4PHeIvi066955 for ; Thu, 25 May 2006 17:40:18 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k4PHeIOR066954; Thu, 25 May 2006 17:40:18 GMT (envelope-from gnats) Resent-Date: Thu, 25 May 2006 17:40:18 GMT Resent-Message-Id: <200605251740.k4PHeIOR066954@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Kurt Miller Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1B57416ACB2 for ; Thu, 25 May 2006 17:38:29 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4D06B43D58 for ; Thu, 25 May 2006 17:38:26 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k4PHcQao080549 for ; Thu, 25 May 2006 17:38:26 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k4PHcQnt080548; Thu, 25 May 2006 17:38:26 GMT (envelope-from nobody) Message-Id: <200605251738.k4PHcQnt080548@www.freebsd.org> Date: Thu, 25 May 2006 17:38:26 GMT From: Kurt Miller To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: kern/97921: close() socket deadlocks blocked threads X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 May 2006 17:40:44 -0000 >Number: 97921 >Category: kern >Synopsis: close() socket deadlocks blocked threads >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu May 25 17:40:17 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Kurt Miller >Release: 6.1-release >Organization: Intricate Software >Environment: FreeBSD freebsd6-1.zonesville.com 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Sun May 7 04:42:56 UTC 2006 root@opus.cse.buffalo.edu:/usr/obj/usr/src/sys/SMP i386 >Description: When a thread is blocked waiting for data on a socket and another thread closes the socket, the blocked thread remains blocked indefinitely. Both kse and thr have this issue. c_r returns with -1 errno==EBADF. Solaris returns with -1 errno==0. I originally posted this on the freebsd-threads list. Daniel Eischen replied indicating this is not a thread library issue. >How-To-Repeat: #include #include #include #include #include #include #include #include #include #include #include static void * start_routine(void *arg) { int sock1 = (int)arg; struct sockaddr remote_addr; char readBuf; int n, remote_addr_len = sizeof(struct sockaddr); n = recvfrom(sock1, &readBuf, 1, 0, &remote_addr, &remote_addr_len); if (n == -1) { printf("unblocked with errno = %d\n", errno); } return (0); } void buildAddr4(struct sockaddr_in *addr4, int address, short port) { memset((char *) addr4, 0, sizeof(struct sockaddr_in)); addr4->sin_port = htons(port); addr4->sin_addr.s_addr = (uint32_t) htonl(address); addr4->sin_family = AF_INET; } int main() { int sock1; struct sockaddr addr; pthread_t thread1; void *value_ptr; buildAddr4((struct sockaddr_in *)&addr, 0, 0); if ((sock1 = socket(AF_INET, SOCK_DGRAM, 0)) < 0) exit(1); if (bind(sock1, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0) exit(1); pthread_create(&thread1, NULL, start_routine, (void *)sock1); sleep(1); close(sock1); pthread_join(thread1, &value_ptr); return (0); } >Fix: >Release-Note: >Audit-Trail: >Unformatted: