* Tru64 5.1A (and B) socket bug
@ 2003-01-23 23:12 Kevin Layer
2003-01-24 18:48 ` Brian Haley
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Layer @ 2003-01-23 23:12 UTC (permalink / raw)
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 <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#if !defined(m_sun4) || defined(SVR4)
#include <netdb.h>
#endif
/* #include <stdio.h> */
#include <errno.h>
/*
* 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;
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Tru64 5.1A (and B) socket bug
2003-01-23 23:12 Tru64 5.1A (and B) socket bug Kevin Layer
@ 2003-01-24 18:48 ` Brian Haley
2003-01-24 22:48 ` Kevin Layer
0 siblings, 1 reply; 3+ messages in thread
From: Brian Haley @ 2003-01-24 18:48 UTC (permalink / raw)
Kevin Layer wrote:
>
> Anyone else run into this problem? We upgraded to 5.1B to see if it
> was fixed, and it is not.
>
> A C program to demonstrate the problem is below.
I had to modify this program to get it to work:
# diff -c bug.c bug2.c
*** 137,151 ****
{
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) {
--- 142,157 ----
{
toread = (len > 4096? 4096 : len);
! if ((got = read(s,buffer+i,toread)) < 0) {
printf("Wanted to read %d, got %d, errno = %d\n",
toread, got, errno);
exit(1);
}
! len -= got;
! i += got;
}
/* now get eof */
if ((got=read(s,buffer,4096)) != 0) {
read() isn't guaranteed to always return what you ask for.
I'll forward this on to someone else here more familiar with that
code, but to make sure your problem is addressed you should call
the support center and file a formal problem report.
-Brian Haley, Tru64 Unix Networking
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Tru64 5.1A (and B) socket bug
2003-01-24 18:48 ` Brian Haley
@ 2003-01-24 22:48 ` Kevin Layer
0 siblings, 0 replies; 3+ messages in thread
From: Kevin Layer @ 2003-01-24 22:48 UTC (permalink / raw)
Brian, thanks for the response. Very much appreciated.
When we run the modified program on V5.1B (Rev. 2650) we still get the
error:
delta :: ./socketbug2
Wanted to see eof on read, got -1 instead.. errno = 22
delta ::
It works perfectly on V4.0E (Rev. 1091), however:
romeo :: ./socketbug2
romeo ::
From our point of view it is definitely a regression, and not behavior
supported by other UNIX implementations (though, ironically, HP-UX has
some similar issues, I found, from looking at our socket test suites).
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-01-24 22:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-23 23:12 Tru64 5.1A (and B) socket bug Kevin Layer
2003-01-24 18:48 ` Brian Haley
2003-01-24 22:48 ` Kevin Layer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox