Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!amdahl!oliveb!sun!betelgeuse!jamesa From: jamesa%betelgeuse@Sun.COM (James D. Allen) Newsgroups: comp.unix.questions Subject: Re: System crash when using sockets Message-ID: <37990@sun.uucp> Date: 6 Jan 88 09:34:51 GMT References: <86@cui.UUCP> Sender: news@sun.uucp Lines: 38 Summary: Don't Exit with un-Accepted Connections In article <86@cui.UUCP>, Stephane Spahni writes: > I have a question about sockets on Unix: I tried to use a socket between > two processes, and regularly crash the system (i.e. the system is looping > somewhere in the kernel and is doing nothing else !). The only way to > recover is to halt the system (^P HALT on Vax, L1-A on Sun) and reboot > it ! Stephane's program neglects to recognize that read returning 0 (EOF) is different from errno 35 (WOULDBLOCK). In the former case, the other end has closed its connection so it's time to try another accept(). This is no excuse for the kernel hang of course. (The faulty zomby disables interrupts; otherwise it would just be another "something is hung (wont die)".) The fact that this bug has not been fixed yet suggests that very few programmers out there are trying to "accept connections". The hang arises when soclose() tries to empty so_q but can't. I don't have an authoritative fix but sofree() will eventually do the cleanup so just deleting the first block of code in soclose() lets my machine run Stephane's "test". For you kids who want to duplicate Stephane's crash, the following should suffice: #include #include short ugly[] = { AF_UNIX, 'GU', 'YL', 0 }; main() { int sr = socket(AF_UNIX, SOCK_STREAM, 0); int sw = socket(AF_UNIX, SOCK_STREAM, 0); bind(sr, ugly, 6); listen(sr, 1); connect(sw, ugly, 6); } /* -- james allen */