From owner-freebsd-bugs Fri May 17 13:37: 2 2002 Delivered-To: freebsd-bugs@freebsd.org Received: from rchss001.chiaro.com (rchss001.chiaro.com [63.88.196.81]) by hub.freebsd.org (Postfix) with SMTP id 2E74A37B409 for ; Fri, 17 May 2002 13:36:56 -0700 (PDT) Received: (qmail 22060 invoked from network); 17 May 2002 20:30:15 -0000 Received: from rchss001.chiaro.com (HELO mail.chiaro.com) (63.88.196.81) by rchss001.chiaro.com with SMTP; 17 May 2002 20:30:15 -0000 Received: from chiaro.com (192-168-25-179.chiaro.com [192.168.25.179]) by mail.chiaro.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id KVSX6LMM; Fri, 17 May 2002 15:36:30 -0500 Message-ID: <3CE569C7.5010104@chiaro.com> Date: Fri, 17 May 2002 15:36:23 -0500 From: Dave Baukus User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: en-us MIME-Version: 1.0 To: freebsd-bugs@freebsd.org Subject: ptheread hang Content-type: multipart/mixed; boundary="=_IS_MIME_Boundary" Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org --=_IS_MIME_Boundary Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit In bsd4.0 it is possible to hang a pthread indefinitely due to what I think is an incorrect interpretation of EAGAIN from the connect() system call. A TCP, and probably a UDP, connect() will return EAGAIN if all the ephemeral ports are allocated. EAGAIN is bubbled up from in_pcbbind() when the connecting socket requires an implicit bind() and the specified ephemeral port range is 100% allocated. When EAGAIN is returned to the pthread _connect() implementation it puts the thread to sleep and waits for poll()/select() to indicate that the connect is complete: from bsd4.0/src/lib/libc_r/uthread/uthread_connect.c: int _connect(int fd, const struct sockaddr * name, socklen_t namelen) { struct sockaddr tmpname; int errnolen, ret, tmpnamelen; if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { if ((ret = _thread_sys_connect(fd, name, namelen)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EALREADY) || (errno == EAGAIN))) { _thread_run->data.fd.fd = fd; /* Set the timeout: */ _thread_kern_set_timeout(NULL); _thread_kern_sched_state(PS_FDW_WAIT, __FILE__,_LINE__); ... ... ... The connect will never complete because it was never started; the TCP never sent a SYN; it is in the closed state; it will remain like this forever. EAGAIN is not the same as EINPROGRESS. -- dave baukus@chiaro.com Chiaro Networks Richardson Texas USA --=_IS_MIME_Boundary Content-Type: text/plain;charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline ----------------------------------------- (on rchss001) This e-mail and any files transmitted with it are the property of Chiaro Networks, Ltd., and may contain confidential and privileged material for the sole use of the intended recipient(s) to whom this e-mail is addressed. If you are not one of the named recipient(s), or otherwise have reason to believe that you have received this message in error, please notify the sender and delete all copies from your system. Any other use, retention, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. --------------------------------------------------------- --=_IS_MIME_Boundary-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message