Connections in TIME_WAIT after unclean exit on local machine

Stanislav Meduna (stano@trillian.eunet.sk)
Sun, 21 Feb 1999 10:28:54 +0100 (CET)


Hello,

the following (not quite correct) code leaves a connection
in TIME_WAIT state for one minute after an exit without shutdown.
Is there some reason not to clear the connection immediately,
when the both sides belong to local machine?

The interesting fact is that if I uncomment the write on the
accept side, the connection _is_ cleared. Similar ~rite on the
connect side does not have such effect.

Uniprocessor PPro, Linux 2.2.1, glibc 2.0.7, egcs 1.1.1
for both kernel and app.

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <signal.h>

main()
{
int fd, sock;
struct sockaddr_in sa;
char foo[65536];

sa.sin_family = AF_INET;
sa.sin_port = htons(9999);
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

signal(SIGCHLD, SIG_IGN);

if (fork() == 0)
{
struct sockaddr_in aa;
int al;

sock = socket(AF_INET, SOCK_STREAM, 0);
bind(sock, &sa, sizeof(sa));
listen(sock, 5);
fd = accept(sock, &aa, &al);
/* write(fd, foo, 10000); */
sleep(2);
}
else
{
sleep(2);
sock = socket(AF_INET, SOCK_STREAM, 0);
fd = connect(sock, &sa, sizeof(sa));
}
}

% netstat --ip
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:1040 localhost:9999 TIME_WAIT

Regards

-- 
					Stano

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/