From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,5050bbe275e896ef,start X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2003-01-23 15:12:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed-east.nntpserver.com!nntpserver.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail NNTP-Posting-Date: Thu, 23 Jan 2003 17:12:01 -0600 Sender: layer@crikey Newsgroups: comp.unix.tru64 Subject: Tru64 5.1A (and B) socket bug From: Kevin Layer Date: 23 Jan 2003 15:12:00 -0800 Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 64.81.254.34 X-Trace: sv3-TAwIhXhwgPHzUjrApPp1XYRiFdU48pxhzjVVDqXZMhrMymkHHBP/xubNomktnIiyN5+kKakwBAz4yt+!KacgyCEZII+oThUgI0NHiP2sK97Cy6IbCOf9aGWjdJ2E1dyC8icBM+/zfF8l1pjSnLbU84/ICB2q!kNIHCJn+paGJU2016++XIESnU03ke66exgmEnI/P X-Complaints-To: abuse@speakeasy.net X-DMCA-Complaints-To: abuse@speakeasy.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.unix.tru64:9436 Anyone else run into this problem? We upgraded to 5.1B to see if it was fixed, and it is not. We're writing from socket A to socket B, then shutting down the output side of socket A. Then we write from socket B to socket A and close socket B completely. At this point the operating system realizes that it need only deliver to the application what's left in A's buffer. So it shuts down the network connection and sits waiting for reads from socket A. The reads work up to and including the partial read that delivers the last bits of information in A's buffer. At this point the operating system gets ahead of itself. It realizes that it's delivered the last bit of information in the buffer and it prematurely shuts down the network socket, and maybe puts some data structs back in the memory pool. Thus when the next read comes in, the one that should return 0 indicating EOF, what the OS finds is that the file descriptor no longer points to anything reasonable in the kernel so the 'invalid argument' error is returned (meaning that the file descriptor is bogus). A C program to demonstrate the problem is below. delta% uname -a OSF1 delta V5.1 2650 alpha delta% cc -o bug bug.c delta% ./bug Wanted to see eof on read, got -1 instead.. errno = 22 delta% ******************************************************************************* #include #include #include #if !defined(m_sun4) || defined(SVR4) #include #endif /* #include */ #include /* * demonstrate bug in Tru64 V5.x * (this works correctly in Digital UNIX V4.0E (Rev. 1091) * * cc -o socketbug socketbug.c * ./aocketbug * * when the error occurs you see * Wanted to see eof on read, got -1 instead.. errno = 22 * * when it works correctly no message is printed */ #define BufSize 50000 main() { char buff[BufSize]; int port, passive_sock, socketa, socketb; struct sockaddr_in sck; int socklen = sizeof(sck); passive_sock = make_passive_socket(&port); socketa = connect_to_socket(port); socketb = accept(passive_sock, (struct sockaddr *) &sck, &socklen); close(passive_sock); write_bytes(socketa,buff,BufSize); shutdown(socketa,SHUT_WR); read_bytes(socketb,buff, BufSize); write_bytes(socketb, buff, BufSize); close(socketb); read_bytes(socketa,buff, BufSize); close(socketa); } int make_passive_socket(int *port) { struct sockaddr_in sck; int socklen = sizeof(sck); int s; if ((s=socket(PF_INET, SOCK_STREAM, 0)) < 0) errnodie(); sck.sin_family = AF_INET; sck.sin_port = htons((short)0); sck.sin_addr.s_addr = htonl((127 << 24) + 1); if (bind(s,(struct sockaddr *) &sck, sizeof(sck)) < 0) errnodie(); listen(s,10); /* get port number */ if (getsockname(s, (struct sockaddr *)&sck, &socklen) < 0) errnodie(); *port = ntohs(sck.sin_port); return s; } int connect_to_socket(port) { /* connect to the given port on localhost */ int s; struct sockaddr_in sck; if ((s=socket(PF_INET, SOCK_STREAM, 0)) < 0) errnodie(); memset(&sck, 0, sizeof(sck)); sck.sin_family = AF_INET; sck.sin_addr.s_addr = htonl((127 << 24) + 1); sck.sin_port = htons((short)port); if (connect(s,(struct sockaddr *) &sck, sizeof(sck)) < 0) errnodie(); return s; } int write_bytes(int s, char *buffer, int len) { int i = 0; int towrite; while (len > 0) { towrite = (len > 4096 ? 4096 : len); if (write(s,buffer+i,towrite) != towrite) fail("didn't write as much as it should have"); len -= towrite; i += towrite; } return 0; } int read_bytes(int s, char *buffer, int len) { int i=0; int toread; int got; while (len > 0) { toread = (len > 4096? 4096 : len); if ((got= read(s,buffer+i,toread)) != toread) { printf("Wanted to read %d, got %d, errno = %d\n", toread, got, errno); exit(1); } len -= toread; i += toread; } /* now get eof */ if ((got=read(s,buffer,4096)) != 0) { printf("Wanted to see eof on read, got %d instead.. errno = %d\n", got, errno); } return 0; } int errnodie() { printf("Failed with errno %d\n", errno); exit(1); return 0; } int fail(char *message) { printf(message); exit(1); return 0; }