Bug #2329
closedconnection was dropped after accept()
Description
Using mod_fastcgi (1.4.28) with php-fpm (5.3.5) over TCP to localhost on FreeBSD 8. Some percentage of the requests fail with this error:
2011-07-21 13:57:32: (mod_fastcgi.c.3094) connection was dropped after accept() (perhaps the fastcgi process died), write-offset: 0 socket: tcp:127.0.0.1:9000
There appears to be a race because fcgi_write_request doesn't verify that the socket is connected/writable when
it is called in the CONNECT_DELAYED state.
The attached patch fixes the issue.
Files
Updated by stbuehler over 13 years ago
- Status changed from New to Invalid
not writable would result in EAGAIN, which is not recognized as "connection drop". and not all systems support poll...
Updated by rr over 13 years ago
- File test-connect-race.c test-connect-race.c added
- File patch-connect-race-network_freebsd_sendfile.c patch-connect-race-network_freebsd_sendfile.c added
- Status changed from Invalid to Reopened
writev() definitely returns ENOTCONN before the socket is connected. Try it yourself with the attached test.
Also attached a FreeBSD-specific patch to address issue as "EAGAIN".
Updated by stbuehler over 13 years ago
well, async connecting is a little bit more difficult than what is used in mod_fastcgi.
Updated by mouk.naj about 13 years ago
any chance of this patch making its way into lighttpd source tree? we been running it on a number of heavily loaded lighttpd servers on freebsd here at WhatsApp without any issues.
Updated by stbuehler about 13 years ago
The question is: can it happen that sendfile gets ENOTCONN as in "and won't be connected ever"? you just assume ENOTCONN means "not yet connected".
Updated by gstrauss almost 9 years ago
Is the problem in this ticket still reproducible in FreeBSD 10?
mod_fastcgi is checking connect()ing socket for writability (POLLOUT) prior to attempting to write to socket. When detected as writable, mod_fastcgi checks getsockopt SO_ERROR to check that there was no socket error. This is an idiom I see quite often. Is there a different way to detect a connected socket on FreeBSD 8? The FreeBSD manpages suggest that what mod_fastcgi is doing is the right way to detect asynchronous connect has completed (or failed).
From FreeBSD man page for 'connect'
https://www.freebsd.org/cgi/man.cgi?query=connect&sektion=2&apropos=0&manpath=FreeBSD+10.2-RELEASE
[EINPROGRESS] The socket is non-blocking and the connection cannot be completed immediately. It is possible to select(2) for completion by selecting the socket for writing.
https://www.freebsd.org/cgi/man.cgi?query=setsockopt&sektion=2
SO_ERROR returns any pending error on the socket and clears the error status. It may be used to check for asynchronous errors on connected datagram sockets or for other asynchronous errors.
Updated by stbuehler almost 9 years ago
- Related to Bug #2316: FreeBSD fastcgi broken: connection was dropped after accept() added
Updated by gstrauss over 8 years ago
Please close ticket: Missing Feedback.
If this is still a problem, please reopen ticket and provide new details. Thank you.
Updated by gstrauss over 8 years ago
- Status changed from Reopened to Missing Feedback
If this is still a problem, please reopen ticket and provide new details. Thank you.
Also available in: Atom