From owner-freebsd-bugs@FreeBSD.ORG Fri May 14 03:50:27 2004 Return-Path: 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 BF6AE16A4CE for ; Fri, 14 May 2004 03:50:27 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5875243D46 for ; Fri, 14 May 2004 03:50:26 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i4EAoPKI075611 for ; Fri, 14 May 2004 03:50:25 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i4EAoPJF075610; Fri, 14 May 2004 03:50:25 -0700 (PDT) (envelope-from gnats) Resent-Date: Fri, 14 May 2004 03:50:25 -0700 (PDT) Resent-Message-Id: <200405141050.i4EAoPJF075610@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, Fabien MENEMENLIS Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E8F4A16A4CE for ; Fri, 14 May 2004 03:43:54 -0700 (PDT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 866CD43D2F for ; Fri, 14 May 2004 03:43:54 -0700 (PDT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i4EAhsPI019056 for ; Fri, 14 May 2004 03:43:54 -0700 (PDT) (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.11/8.12.11/Submit) id i4EAhsNW019055; Fri, 14 May 2004 03:43:54 -0700 (PDT) (envelope-from nobody) Message-Id: <200405141043.i4EAhsNW019055@www.freebsd.org> Date: Fri, 14 May 2004 03:43:54 -0700 (PDT) From: Fabien MENEMENLIS To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: misc/66629: socket connecting with itself (race condition?) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 May 2004 10:50:28 -0000 >Number: 66629 >Category: misc >Synopsis: socket connecting with itself (race condition?) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri May 14 03:50:24 PDT 2004 >Closed-Date: >Last-Modified: >Originator: Fabien MENEMENLIS >Release: 4.9-STABLE >Organization: Iliad >Environment: FreeBSD huge.dir.com 4.9-STABLE FreeBSD 4.9-STABLE #2: Fri Mar 5 15:58:16 CET 2004 fabien@huge.iliad.fr:/usr/obj/usr/src/sys/DUAL i386 >Description: When connecting to a closed local port in PF_INET space with many clients, it happens once in a while that connect() succeeds. The output of netstat -A for the given connection is then: ea2c0e40 tcp4 0 0 localhost.4555 localhost.4555 ESTABLISHED I've not been able to reproduce the problem on a 5.2.1 environment. >How-To-Repeat: I know I shouldn't submit code here but it's pretty simple. For better readability see http://dir.com/testsock.c #include #include #include #include #include #include #include #include #define MAXFORK 100 int sockconnect(char *nomserv, int noport) { struct sockaddr_in serv; struct hostent *host; int sock; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) return(-1); if ((host = gethostbyname(nomserv)) == NULL) return(-1); serv.sin_family = AF_INET; serv.sin_port = htons(noport); memcpy(&serv.sin_addr, host->h_addr, host->h_length); if (connect(sock, (struct sockaddr *)&serv, sizeof(struct sockaddr_in)) == -1) { close(sock); return(-1); } return(sock); } int main(void) { int i; int s; for (i = 0; i < MAXFORK; i++) { if (fork() == 0) { for (;;) { s = sockconnect("localhost", 4555); if (s != -1) { printf("connected... (s=%d)\n", s); } sleep(1); } } } } >Fix: >Release-Note: >Audit-Trail: >Unformatted: