Date: Fri, 14 May 2004 03:43:54 -0700 (PDT) From: Fabien MENEMENLIS <fabien@iliad.fr> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/66629: socket connecting with itself (race condition?) Message-ID: <200405141043.i4EAhsNW019055@www.freebsd.org> Resent-Message-ID: <200405141050.i4EAoPJF075610@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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 <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <netdb.h> #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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200405141043.i4EAhsNW019055>