I have just rolled out the latest dev build of sqwebmail onto our live system, to give the FastCGI fixes a workout, and I discover that I get more and more processes which are stuck in an infinite loop handling SIGPIPE - see below. They don't respond to a normal kill, only kill -9 will zap them.
There seems to be some very complex signal handling code in sqwebmail.c for fastcgi, doing some strange things with setjmp/longjmp, and I don't fully understand what it's trying to do. I've done a bit of FastCGI development work before, and here's what I remember: - If Apache sends a SIGUSR1 then this is a signal for graceful termination. The app can finish the current request if it is in the middle of handling one, otherwise it should terminate immediately - If the app is sending out data but the client has gone away, then the O/S will send a SIGPIPE. The app can simply ignore this. If it is a clever app then it can cease processing the current request early. The FastCGI library installs handlers for SIGUSR1 and SIGPIPE (if they are currently set to SIG_DFL), and the handlers set a flag. If the main accept() in FCGI_Accept is interrupted by the USR1 signal, then it returns EINTR; the flag is tested, and FCGI_Accept returns immediately. A null SIGPIPE handler is installed, so that it is just ignored. ISTM that if sqwebmail wants to install cleanup handlers for SIGINT / SIGTERM / SIGHUP then it should just cleanup the current request and exit() immediatetly, not longjmp back into the main loop. In the case of SIGPIPE well, it can cleanup and longjmp back into the main loop - except that doesn't seem to be working at the moment. It would be better just to ignore SIGPIPE, in which case the process just completes handling the current request and then goes back into its main loop. Regards, Brian. # kdump -T | head -50 13779 sqwebmail 1059400903.900820 RET sigaction 0 13779 sqwebmail 1059400903.900894 CALL sigaction(0xd,0xbfbffd54,0xbfbffd3c) 13779 sqwebmail 1059400903.900903 RET sigaction 0 13779 sqwebmail 1059400903.900909 CALL sigaction(0xf,0xbfbffd44,0xbfbffd2c) 13779 sqwebmail 1059400903.900915 RET sigaction 0 13779 sqwebmail 1059400903.900928 CALL write(0x3,0x80c5000,0x2000) 13779 sqwebmail 1059400903.900940 PSIG SIGPIPE caught handler=0x8070df4 mask=0x0 code=0x0 13779 sqwebmail 1059400903.900951 RET write -1 errno 32 Broken pipe 13779 sqwebmail 1059400903.900967 CALL sigprocmask(0x3,0x80bbc7c,0) 13779 sqwebmail 1059400903.900974 RET sigprocmask 0 13779 sqwebmail 1059400903.900982 CALL sigaction(0x1,0xbfbffd54,0xbfbffd3c) 13779 sqwebmail 1059400903.900989 RET sigaction 0 13779 sqwebmail 1059400903.900994 CALL sigaction(0x2,0xbfbffd44,0xbfbffd2c) 13779 sqwebmail 1059400903.901000 RET sigaction 0 13779 sqwebmail 1059400903.901005 CALL sigaction(0xd,0xbfbffd54,0xbfbffd3c) 13779 sqwebmail 1059400903.901011 RET sigaction 0 13779 sqwebmail 1059400903.901017 CALL sigaction(0xf,0xbfbffd44,0xbfbffd2c) 13779 sqwebmail 1059400903.901022 RET sigaction 0 13779 sqwebmail 1059400903.901029 CALL write(0x3,0x80c5000,0x2000) 13779 sqwebmail 1059400903.901036 PSIG SIGPIPE caught handler=0x8070df4 mask=0x0 code=0x0 13779 sqwebmail 1059400903.901044 RET write -1 errno 32 Broken pipe 13779 sqwebmail 1059400903.901051 CALL sigprocmask(0x3,0x80bbc7c,0) 13779 sqwebmail 1059400903.901057 RET sigprocmask 0 13779 sqwebmail 1059400903.901063 CALL sigaction(0x1,0xbfbffd54,0xbfbffd3c) 13779 sqwebmail 1059400903.901069 RET sigaction 0 13779 sqwebmail 1059400903.901075 CALL sigaction(0x2,0xbfbffd44,0xbfbffd2c) 13779 sqwebmail 1059400903.901081 RET sigaction 0 13779 sqwebmail 1059400903.901086 CALL sigaction(0xd,0xbfbffd54,0xbfbffd3c) 13779 sqwebmail 1059400903.901092 RET sigaction 0 13779 sqwebmail 1059400903.901097 CALL sigaction(0xf,0xbfbffd44,0xbfbffd2c) 13779 sqwebmail 1059400903.901103 RET sigaction 0 13779 sqwebmail 1059400903.901109 CALL write(0x3,0x80c5000,0x2000) 13779 sqwebmail 1059400903.901116 PSIG SIGPIPE caught handler=0x8070df4 mask=0x0 code=0x0 13779 sqwebmail 1059400903.901124 RET write -1 errno 32 Broken pipe 13779 sqwebmail 1059400903.901131 CALL sigprocmask(0x3,0x80bbc7c,0) 13779 sqwebmail 1059400903.901170 RET sigprocmask 0 13779 sqwebmail 1059400903.901178 CALL sigaction(0x1,0xbfbffd54,0xbfbffd3c) 13779 sqwebmail 1059400903.901185 RET sigaction 0 13779 sqwebmail 1059400903.901191 CALL sigaction(0x2,0xbfbffd44,0xbfbffd2c) 13779 sqwebmail 1059400903.901196 RET sigaction 0 13779 sqwebmail 1059400903.901202 CALL sigaction(0xd,0xbfbffd54,0xbfbffd3c) 13779 sqwebmail 1059400903.901207 RET sigaction 0 13779 sqwebmail 1059400903.901213 CALL sigaction(0xf,0xbfbffd44,0xbfbffd2c) 13779 sqwebmail 1059400903.901219 RET sigaction 0 13779 sqwebmail 1059400903.901225 CALL write(0x3,0x80c5000,0x2000) 13779 sqwebmail 1059400903.901232 PSIG SIGPIPE caught handler=0x8070df4 mask=0x0 code=0x0 13779 sqwebmail 1059400903.901241 RET write -1 errno 32 Broken pipe 13779 sqwebmail 1059400903.901248 CALL sigprocmask(0x3,0x80bbc7c,0) 13779 sqwebmail 1059400903.901254 RET sigprocmask 0 13779 sqwebmail 1059400903.901261 CALL sigaction(0x1,0xbfbffd54,0xbfbffd3c)
